Results 1 to 3 of 3

Thread: Text file processing

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Location
    North east UK
    Posts
    129

    Text file processing

    Hi All,

    I am trying to import a text file into a database and am having difficulties with how the text file is storing the data, example below:

    ---Text file start---

    Name:
    Joe Bloggs

    Age:
    21

    Address:
    Somewhere

    Name:
    Bob Builder

    Age:
    65

    Address:
    anywhere

    ---Text file end---

    This is how the records are stored, but what i need to do is pull both of these records out of the text file and insert them into an access database. The problem is that when I try standard imports, they do not pick up the field names and import the text file as a single list as it appears in the text file.

    Any ideas on how to import this using a tool or with code appreciated.

    dagoose

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    Here is some from one of my systems where I import data from a text file.

    rs.Open "payrolltransactionhistory", Cnxn, adOpenKeyset, adLockOptimistic, adCmdTable
    Open "z:\PR\PAYROLLTRANSHISTORY.csv" For Input As #2
    Do While Not EOF(2)
    Input #2, EMPLOYEEID, TRXBEGINNINGDATE, TRXENDINGDATE, UNITSTOPAY, PAYRATE, PAYROLLCODE, PAYROLLRECORDTYPE, UPRTRXAMOUNT
    rs.AddNew
    rs![EMPLOYEEID] = EMPLOYEEID
    rs![TRXBEGINNINGDATE] = CDate(TRXBEGINNINGDATE)
    rs![TRXENDINGDATE] = CDate(TRXENDINGDATE)
    rs![UNITSTOPAY] = CSng(UNITSTOPAY)
    rs![PAYRATE] = CSng(PAYRATE)
    rs![PAYROLLCODE] = PAYROLLCODE
    rs![PAYROLLRECORDTYPE] = PAYROLLRECORDTYPE
    rs![UPRTRXAMOUNT] = CSng(UPRTRXAMOUNT)
    rs.Update
    Loop
    Close #2
    rs.Close

  3. #3
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Export a sample database to a textfile first so you'll know the format necessary to import using the standard thingy.

    Otherwise, you have to parse the file into a format you can use to save to the database.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width