Results 1 to 6 of 6
  1. #1
    stalk is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    143

    Read basic .txt file into Access using VBA

    How can I read a .txt file completely into temp table and identify the line "Instrument Serial Number" and capture the value into a variable for a specific purpose.

    .txt file attached it has 800 lined but I only have few line in the attached file.

    Thank you in advance
    Attached Files Attached Files

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    adjust as you need:

    Code:
    Public Sub ImportTxt()
    Dim vFind, vFile, vNum, vLine
    Dim i As Integer
    vFile = "c:\temp\textfile.txt"
    vFind = "Instrument Serial Number"
    Open vFile For Input As #1
    While Not EOF(1)
       Line Input #1, vLine
       If InStr(vLine, vFind) > 0 Then
           i = InStr(vLine, "=")
           If i > 0 Then
                vNum = Mid(vLine, i + 1)
                MsgBox vNum
                GoTo endit
           End If
       End If
    Wend
    endit:
    Close 1
    End Sub

  3. #3
    stalk is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    143
    Thank you so much. It works perfectly as I wished. Purposed solved.

    But what change should I do to stores all 800 records in temp table because serial number is causing the changes in the line items, so after identifying that VNUM I need to modify the my existing code to read step by step based on the vnum paramater

  4. #4
    stalk is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    143
    Also how do I mark this Solved?

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

  6. #6
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Append query to add it to the table.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-26-2017, 02:09 PM
  2. ACCDE file read only????
    By Jen0dorf in forum Access
    Replies: 10
    Last Post: 11-29-2015, 03:16 PM
  3. Replies: 7
    Last Post: 08-07-2014, 06:07 PM
  4. Replies: 3
    Last Post: 05-23-2012, 03:05 AM
  5. Read text file with LF
    By SteveG in forum Programming
    Replies: 8
    Last Post: 12-24-2011, 09:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums