Results 1 to 2 of 2

Thread: Reading a text file into Access

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2002
    Location
    Tallahassee, Florida
    Posts
    24

    Reading a text file into Access

    I have a text file that has more than one record per line. I know that there are 129 characters per record, but I am not sure how many records there are per line.

    I want to read the txt file and put each 129 characters into a record in access.

  2. #2
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Halifax,UK
    Posts
    274
    heres a function that will do it for you...

    VB Code:
    1. Public Function returnRecordsArray(inFile As String, recLen As Long) As Variant
    2. Dim strIn As String
    3. Dim fileNo As Long
    4. Dim recs() As Variant
    5. Dim count As Integer
    6.  
    7.     fileNo = FreeFile
    8.     Open inFile For Binary As fileNo
    9.     strIn = Input(LOF(fileNo), fileNo)
    10.     strIn = Replace(strIn, vbCrLf, "")
    11.     count = Len(strIn) \ recLen
    12.     ReDim recs(count)
    13.     For count = 0 To (Len(strIn) \ recLen)
    14.         recs(count) = Left(strIn, recLen)
    15.         strIn = Mid(strIn, recLen + 1)
    16.     Next count
    17.     returnRecordsArray = recs
    18. End Function

    now just set a variant array to the function e.g...
    VB Code:
    1. Dim myRecs() As Variant
    2. myRecs = returnRecordsArray("c:\temp\test.txt", 5)

    of course you could change the function to return whatever you wanted
    VB6 VS2005

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