I am using a text file to import data from a text file.
The problem is that the date field variables do not seem to come through. I get Overflow (Error 6) if I try to import the date fields 'Dim ... As Date'. I have set the import table up correctly to Short Date to receive the dates but no joy. The dates import if the variables are set 'As String' but obviously the resulting date displayed is all wrong. Here's my code:
Dim db As DAO.Database, rst As DAO.Recordset
Dim no As Integer
Dim PNo As Long
Dim PNew, POld As Currency
Dim ADPerc As Single
Dim ad1, ad2, ad3, ad4, Sur, notes, rules, title, TypPen, mySQL As String
Dim AdDat, WPen, POldDate, PNewDate, PGranted As Date
Set db = CurrentDb()
Set rst = db.OpenRecordset("Import"
Open "C:\test.txt" For Input As #1
Do Until EOF(1)
Input #1, no, ad1, ad2, ad3, ad4, AdDat, WPen, Sur, PNew, notes, POld, POldDate, PNewDate, PGranted, PNo, ADPerc, rules, title, TypPen
rst.AddNew
rst.Fields("ID"
= no
rst.Fields("Address1"
= ad1
rst.Fields("Address2"
= ad2
rst.Fields("Address3"
= ad3
rst.Fields("Address4"
= ad4
rst.Fields("AdjustDate"
= AdDat
rst.Fields("WidowsPen"
= WPen
rst.Fields("Surname"
= Sur
rst.Fields("PensionNewAmount"
= PNew
rst.Fields("Notes"
= notes
rst.Fields("PensionOldAmount"
= POld
rst.Fields("PensionOldDate"
= POldDate
rst.Fields("PensionNewDate"
= PNewDate
rst.Fields("PensionGranted"
= PGranted
rst.Fields("PensionNo"
= PNo
rst.Fields("AdjustmentPercentage"
= ADPerc
rst.Fields("Rules"
= rules
rst.Fields("TitleInitials"
= title
rst.Fields("TypeOfPension"
= TypPen
rst.Update
Loop
Set db = Nothing
Set rst = Nothing
Close #1
The problem is that the date field variables do not seem to come through. I get Overflow (Error 6) if I try to import the date fields 'Dim ... As Date'. I have set the import table up correctly to Short Date to receive the dates but no joy. The dates import if the variables are set 'As String' but obviously the resulting date displayed is all wrong. Here's my code:
Dim db As DAO.Database, rst As DAO.Recordset
Dim no As Integer
Dim PNo As Long
Dim PNew, POld As Currency
Dim ADPerc As Single
Dim ad1, ad2, ad3, ad4, Sur, notes, rules, title, TypPen, mySQL As String
Dim AdDat, WPen, POldDate, PNewDate, PGranted As Date
Set db = CurrentDb()
Set rst = db.OpenRecordset("Import"
Open "C:\test.txt" For Input As #1
Do Until EOF(1)
Input #1, no, ad1, ad2, ad3, ad4, AdDat, WPen, Sur, PNew, notes, POld, POldDate, PNewDate, PGranted, PNo, ADPerc, rules, title, TypPen
rst.AddNew
rst.Fields("ID"
rst.Fields("Address1"
rst.Fields("Address2"
rst.Fields("Address3"
rst.Fields("Address4"
rst.Fields("AdjustDate"
rst.Fields("WidowsPen"
rst.Fields("Surname"
rst.Fields("PensionNewAmount"
rst.Fields("Notes"
rst.Fields("PensionOldAmount"
rst.Fields("PensionOldDate"
rst.Fields("PensionNewDate"
rst.Fields("PensionGranted"
rst.Fields("PensionNo"
rst.Fields("AdjustmentPercentage"
rst.Fields("Rules"
rst.Fields("TitleInitials"
rst.Fields("TypeOfPension"
rst.Update
Loop
Set db = Nothing
Set rst = Nothing
Close #1