Windows Vista Forums

Importing text file to Access Database

  1. #1


    Codeblack Guest

    Importing text file to Access Database

    Hi,

    Does any one know how to import a delimeted text file into access database
    using VBscript. Any suggestions is appreciated.

    Thanks

      My System SpecsSystem Spec

  2. #2


    Codeblack Guest

    RE: Importing text file to Access Database

    The data is something like this.

    abc.rtd@xxxxxx,unknown,google.com,290447512478,714

      My System SpecsSystem Spec

  3. #3


    hb21l6 Guest

    Re: Importing text file to Access Database


    "Codeblack" <Codeblack@xxxxxx> wrote in message
    news:F68F65F2-4FEE-4015-BEE5-EE89EFFF074A@xxxxxx

    > The data is something like this.
    >
    > abc.rtd@xxxxxx,unknown,google.com,290447512478,714
    >
    that depends on how much in depth you want to go with it,

    Firstly, you need to read the txt file..

    myFile = "C:\mytextFile"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(myFile,1)

    If objFSO.FileExists(HFiles) Then
    ' see if the file exists and open it
    Set HFile = objFSO.OpenTextFile(myFile,8, True)
    else
    ' Create a Header file
    Set HFile = objFSO.CreateTextFile(myFile, True)
    End If


    THIS IS HOW YOU MAKE A CONNECTION TO A msACCESS DATABASE

    Set dbConn= Server.CreateObject("ADODB.Connection")
    sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
    Source=C:\db2.mdb;Persist Security Info=False"
    dbConn.Open(sConnString)
    SET rsupdate = server.createObject("adodb.recordset")

    Do Until objFile.AtEndOfLine
    ' here is your line of data.
    line=objFile.ReadLine
    ' you now need to split this line using the Split() object to parse out each
    field from the line


    SQL = "insert into tbl_name (field1, field2 field3, etc) values ('" & val1 &
    "', " & val2 & ", '" & val3 & "')"

    SET rsupdate = dbconn.execute(SQL)


    Loop

    set rsupdate = nothing
    set dbconn = nothing



    YOU WILL NEED TO ALTER THIS TO SUITE YOUR NEEDS.



    Dave




      My System SpecsSystem Spec

  4. #4


    Codeblack Guest

    Re: Importing text file to Access Database

    Thanks Dave. Will try this out. Thanks for your suggestion.

    Regards
    Codeblack

      My System SpecsSystem Spec


Importing text file to Access Database
Similar Threads
Thread Forum
Get custom database properties from an Access database VB Script
Runtime Error 75 path/file access error on call from access database System Security
Export Microsoft Access Database to Text File .NET General
Convert hostname text file to IP text file VB Script
comma delimited text file into database PowerShell