Results 1 to 3 of 3
  1. #1
    newbie is offline Advanced Beginner
    Windows XP Access 97
    Join Date
    May 2009
    Posts
    34

    Question Import Row 1 Only on a .txt File


    Every two weeks I receive 116 text files. For every file I need to extract the total number of records so that I can perform a calculation later on. this information happens to be in the header row of my files. Is it possible to import just the header row (row 1) and append it to a table in Access? I would really like to avoid opening all 116 records and then manually populating a control. Any suggestions are VERY welcome!

    Thanks

  2. #2
    ajetrumpet is offline Banned
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    one way that I can think of is to read the first line through a string variable with a function. One such function would be something like:
    Code:
    Function TxtReadLn(wPath As String, _
                       Optional lnNum As Long)
    
    '******************************************************************************
    '                                                                             *
    'Author: Adam Evanovich                                                       *
    'Date: 6/12/2006                                                              *
    'Purpose: Reads a single line of text from a text file.                       *
    '                                                                             *
    'Arguments:                                                                   *
    'wPath > Full path of the text file being read.                               *
    'lnNum > The line number to read.  If omitted, the first line of text will    *
    '        be read.  If invalid, it returns and error.                          *
    '                                                                             *
    '******************************************************************************
    
    On Error GoTo Err_Handle
    
    Const wMode = 1& 'Read Only Mode - Long Value
    
    Dim ctr As Long
    Dim fso As Object
    Dim oFile As Object
    Dim tStream As Object
    
    ctr = 1
    
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set oFile = fso.GetFile(wPath)
       Set tStream = oFile.OpenAsTextStream(wMode)
       
          If lnNum > 0 Then
          
             On Error GoTo Err_Handle_EOS
             
                Do While ctr < lnNum
                   tStream.SkipLine
                      ctr = ctr + 1
                Loop
          
          End If
    
    On Error GoTo Err_Handle
    
             TxtReadLn = tStream.ReadLine
                tStream.Close
    
        Set fso = Nothing
        Set oFile = Nothing
        Set tStream = Nothing
        
    Exit Function
    
    Err_Handle:
    
        If Err.Number = 53 Then
            MsgBox "There is no file to read..."
        End If
    
          Set fso = Nothing
          Set oFile = Nothing
          Set tStream = Nothing
    
    Err_Handle_EOS:
    
       MsgBox "Line number is invalid..."
       
          Set fso = Nothing
          Set oFile = Nothing
          Set tStream = Nothing
    
    End Function
    You could also import the txt using code, then append the first row however you need it. that would take a lot less code too.

  3. #3
    thhui is offline Competent Performer
    Windows XP Access 2002
    Join Date
    Feb 2009
    Posts
    235
    Use any programs or vba to read the first line of data of the file and save it with original_filename_1.txt.
    Then use those files to import.

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

Similar Threads

  1. Replies: 5
    Last Post: 10-19-2010, 09:10 AM
  2. Import XML file
    By randolphoralph in forum Programming
    Replies: 1
    Last Post: 01-22-2010, 09:12 PM
  3. Import prn file
    By Accessshelp@work in forum Import/Export Data
    Replies: 1
    Last Post: 10-29-2009, 09:16 AM
  4. Import a .sql file?
    By Alan in forum Import/Export Data
    Replies: 1
    Last Post: 06-03-2009, 07:52 PM
  5. CSV File Import
    By compasst in forum Import/Export Data
    Replies: 3
    Last Post: 03-31-2006, 09:37 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