Importing Txt Files

  • Thread starter Thread starter Gary Hall
  • Start date Start date
G

Gary Hall

When importing text files using the Import Txt Wizard I
regulary, but not always, get a pop-up message which
says "Invalid Argument". Does anyone out there no why this
would be and if so how it can be got around. I am trying
to import a million plus records, however I am lead to
believe that this is within a .mdb capabilities.

Cheers in advance

Gary
 
1. Try it in a small sample of the data in the file (first 10 rows or so.)
2. Try it on other files.
Does it work?

If so, then the problem is in your data somewhere.
(Invalid dates, Null values, etc.)

You could try importing without the wizard.
Something like this:

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