I/O .txt files into MS-Access


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: I/O .txt files into MS-Access

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    I/O .txt files into MS-Access

    [Originally posted by msprb]

    The task at hand is using an Access Module, to input a .txt file saved in a local dir, and then to put that information on a table. I also need to Parse the columns, and see if a particular record exists in a table, if not then append the record, otherwise update the existing record.˙ If someone knows a way around this please lemme know

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:I/O .txt files into MS-Access

    [Originally posted by Ravi]

    hi,
    yes, this is possible. but b4 can u tell me like:
    is ur text file˙ contains fixed number˙ of˙ record length, field lenght. then u can read column by column for each row, u can search ur table for duplicacy also and then u can append the record also.
    let me know, if u hv queries.
    bye
    ravi

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:I/O .txt files into MS-Access

    [Originally posted by msprb]

    The text file doesn't contain a fixed number of rows, but it does have a fixed number of fields, 6 to be exact, but im only dealing with tables, no queries involved, thanks.

  4. #4
    Join Date
    Aug 2004
    Posts
    43,023

    Re:I/O .txt files into MS-Access

    [Originally posted by Jim]

    try something like this.

    dim x as integer
    dim y as integer
    dim flds(6) as string
    dim db as database
    dim str as string
    dim rsRef as recordset


    x = freefile
    set db = currentdb
    set rsref = "db.openrecordset("select * from Mytable")


    open "c:\Myfile.txt" for input as #x
    do while not eof(x)
    line input #x, str
    for y = 0 to 5
    flds(y) = left(str, instr(1,str,",")-1)
    str = mid(str,instr(1,str,",")+1)
    next
    rsref.findfirst("myfield = " & flds(0))
    if rsref.nomatch then
    str = "Insert Into mytable myfield1, myfield2...."
    str = str & "values " & chr(39) & flds(0) & chr(39)
    str = str & ", " & chr(39) & flds(1) & chr(39)
    .
    .
    .
    else
    str = "update mytable set "
    str = str & "Myfield2 = " & chr(39) & flds(1) & chr(39)
    str = str & " Myfield3 = " & chr(39) & flds(2) & chr(39)
    .
    .
    .
    str = str & " where myfield1 = " & chr(39) & flds(0) & chr(39)
    end if
    db.execute str
    str = ""
    loop
    close #x
    rsref.close
    set rsref = nothing
    set db = nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center