Ok Quehay I can see the problem, if you're not sure the text file contains correct info like none in a numeric field or n/a in a date you should import the text in a table with all text coulombs which can be empty.
Then put this table into a record set, put the destination table in a record set en update the destination table checking the source record set (which was the text file) with some if statements.
Function test()
' specify some variables as date or integer so we can do a check later
Dim datevar As Date
Dim integervar As Integer
' you should have a table called temp or the next line will get an error.
‘ in this table we will import the text file
DoCmd.DeleteObject acTable, "temp"
' you should have a saved specs j the g is talking about (in this case its called imp) and put the text file
' in a table called temp
' this table will be made when it is not there
DoCmd.TransferText acImportDelim, "imp", "temp", "c:\backup\test.txt"
' now we are going to open the temp table and put it in a recordset called rstcource
Set rstcource = CurrentDb.OpenRecordset("temp"
' now we are going to open a table called ebanking in a recordset called rstdest this is the table where
‘ the data from the text file should go
Set rstdest = CurrentDb.OpenRecordset("ebanking"
' now we are going to open a table called errors where we put the record with the wrong format
‘ this table should contain 2 text fields which can be zero length and are called numberfield and
‘ datefield
Set rsterr = CurrentDb.OpenRecordset("errors"
' now lets put the source in the destination table
Do Until rstcource.EOF
' the on error statement below jumps to wrong_format if something goes wrong so the record in the table wil not be filled
' allthough if you use a long integer (between -32768 till 32767) you get a script error so an if statement is needed
' this is also the case when the text record was empty
On Error GoTo wrong_format
If rstcource.numberfield > 32767 Or rstcource.numberfield < -32768 Then
GoTo wrong_format
Else
If Not IsNull(rstcource.datefield) Then
datevar = rstcource.datefield
Else
GoTo wrong_format
End If
If Not IsNull(rstcource.numberfield) Then
integervar = rstcource.numberfield
Else
GoTo wrong_format
End If
‘ here the destination table is filled if nothing is wrong, otherwise the error table is filled
rstdest.AddNew
rstdest.numberfield = integervar
rstdest.datefield = datevar
rstdest.checkfield = check
rstdest.Update
‘ here we need to jump to the end otherwise the error record will be filled with all records both good
‘ and bad
GoTo endloop
End If
wrong_format:
‘ here the error table is filled
rsterr.AddNew
rsterr.datefield = rstcource.datefield
rsterr.numberfield = rstcource.numberfield
rsterr.Update
‘ endloop is just a tag to jump to this does not mean the loop end here, the loop ends when there are no more
‘ records in the recordset rstcource
endloop:
‘ goto the next record in rstcource this is verry important because if this does not happen the loop will
‘ never stop
rstcource.MoveNext
Loop
End Function