Import Text Files to Access Tables

G

Glenn Weidner

I am looking for a way to import text files into Access
where the data, including headers, does NOT begin on the
first row. Excel will handle this, but I'm looking to
automate this process with Access. Any suggestions?
 
J

Joe Fallon

Need more info if you want a good answer.
What *deos* the data look like?
Where does it start?

You can always write code to opena file and read it yourself (bypass the
wizards)
Here is an outline for how to get started:

Public Sub ImportFile(strPath As String)

Dim db As Database, rs As Recordset
Dim sLine As String, sTrimmed As String
Set db = CurrentDb
Set rs = db.OpenRecordset("TableName", dbOpenTable)

Open strPath For Input As #1

'Read a single line from an open sequential file and assign it to a String
variable.
Line Input #1, sLine
'Trim the leading blanks
sTrimmed = LTrim(sLine)

Do While Not EOF(1)
'read the next line of the file
Line Input #1, sLine
sTrimmed = LTrim(sLine)

'manipulate the string if necessary, then add it to the rs table.
If rs.BOF = True Then
rs.AddNew
Else
rs.Edit
End If
rs.Update
Loop
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top