Import Text Files to Access Tables

  • Thread starter Thread starter Glenn Weidner
  • Start date Start date
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?
 
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
 
Back
Top