View Single Post
  #6  
Old May 29th, 2010, 02:50 AM posted to microsoft.public.access
PieterLinden via AccessMonster.com
external usenet poster
 
Posts: 307
Default getting data from a text file

Dorian wrote:
Your file is in the wrong format for automatically importing to Access.
You need to get your file into a format like a spreadsheet where you have
the field names going across and the value for each field below the heading.
Each field should either have a fixed width or you can have the fields
separated by commas or some other delimiter.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".

i have an access 2003 database. i have a text file which has loads of
instances of the below text. i want to be able to this data into a table so

[quoted text clipped - 25 lines]
WAVE_FILE=""
}


No, it just means he can't just attach the text file and query it directly.
He can open it in code, look for "DESCRIPTION=", strip out the junk, and
write the value to a table...

Private Sub ParseTextFile(ByVal strFile As String)
Dim intFileNo As Integer
Dim strTextLine As String

intFileNo = FreeFile
Open strFile For Input As #intFileNo

Do While Not EOF(intFileNo) ' Loop until end of file.
Line Input #1, strTextLine ' Read line into variable.
strTextLine = Trim$(strTextLine)
'intCounter = intCounter + 1
If Left$(strTextLine, 12) = "DESCRIPTION=" Then
' PROCESS THE TEXT FILE HERE.
strTextLine = Mid$(strTextLine, 14)
strTextLine = Left$(strTextLine, Len(strTextLine) - 1)

' write the record to your recordset here...
Debug.Print strTextLine
End If
Loop

Close #intFileNo

End Sub

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/201005/1