G
George Atkins
I am using Access 2007 and SQL Server 2000, with MS ADO 2.8 Library (I've
tried other versions, too).
I'm trying to post records from an Access table into SQL Server 2000, but I
error out when trying to add time values stored in a regular Access date/time
field. Error: "Invalid date format" error -2147467259. Here is my code:
Dim cnSQL As ADODB.Connection
Dim rsAU As ADODB.Recordset ' SQL table
Dim rsACC As DAO.Recordset ' the ACCESS tblCurrentAttendanceTemp table
Dim MyMinutes As Integer
On Error GoTo ErrorHandler
Set cnSQL = New ADODB.Connection
Set rsAU = New ADODB.Recordset
Set rsACC = CurrentDb.OpenRecordset("tblCurrentAttendanceTemp",
dbOpenDynaset)
With cnSQL
.Provider = "sqloledb"
.Properties("Data Source").Value = "12.69.31.1"
.Properties("Initial catalog").Value = "rdale" ' Production Server
.Properties("User id").Value = "gka"
.Properties("Password").Value = "nutcase"
.Open
End With
rsAU.Open "AttendanceUnit", cnSQL, adOpenKeyset, adLockOptimistic
With rsACC ' the Access source table
.MoveFirst
While Not .EOF
rsAU.AddNew ' the SQL Server table
rsAU.Fields("CalendarID") = .Fields("CalID")
rsAU.Fields("personID") = .Fields("PID")
rsAU.Fields("sectionID") = .Fields("SecID")
rsAU.Fields("Date") = .Fields("AttendanceDate")
rsAU.Fields("startTime") = .Fields("StartTime") ' THIS FAILS!
rsAU.Fields("endTime") = .Fields("EndTime") ' THIS FAILS,
TOO!
MyMinutes = ((.Fields("EndTime") * 24) - (.Fields("StartTime") *
24)) * 60
rsAU.Fields("units") = MyMinutes
rsAU.Update
.MoveNext
Wend
End With
The Access date fields are standard date/time fields with no special
formatting, storing only entered times, such as 9:30 AM. The SQL "startTime"
and "endTime" fields are SmallDateTime data types.
If I remove the StartTime and EndTime fields, there is no issue with adding
the records, of course. There is also no issue with the AttendanceDate field.
What do I need to do in order to get the SQL table to accept my Access time
values?
tried other versions, too).
I'm trying to post records from an Access table into SQL Server 2000, but I
error out when trying to add time values stored in a regular Access date/time
field. Error: "Invalid date format" error -2147467259. Here is my code:
Dim cnSQL As ADODB.Connection
Dim rsAU As ADODB.Recordset ' SQL table
Dim rsACC As DAO.Recordset ' the ACCESS tblCurrentAttendanceTemp table
Dim MyMinutes As Integer
On Error GoTo ErrorHandler
Set cnSQL = New ADODB.Connection
Set rsAU = New ADODB.Recordset
Set rsACC = CurrentDb.OpenRecordset("tblCurrentAttendanceTemp",
dbOpenDynaset)
With cnSQL
.Provider = "sqloledb"
.Properties("Data Source").Value = "12.69.31.1"
.Properties("Initial catalog").Value = "rdale" ' Production Server
.Properties("User id").Value = "gka"
.Properties("Password").Value = "nutcase"
.Open
End With
rsAU.Open "AttendanceUnit", cnSQL, adOpenKeyset, adLockOptimistic
With rsACC ' the Access source table
.MoveFirst
While Not .EOF
rsAU.AddNew ' the SQL Server table
rsAU.Fields("CalendarID") = .Fields("CalID")
rsAU.Fields("personID") = .Fields("PID")
rsAU.Fields("sectionID") = .Fields("SecID")
rsAU.Fields("Date") = .Fields("AttendanceDate")
rsAU.Fields("startTime") = .Fields("StartTime") ' THIS FAILS!
rsAU.Fields("endTime") = .Fields("EndTime") ' THIS FAILS,
TOO!
MyMinutes = ((.Fields("EndTime") * 24) - (.Fields("StartTime") *
24)) * 60
rsAU.Fields("units") = MyMinutes
rsAU.Update
.MoveNext
Wend
End With
The Access date fields are standard date/time fields with no special
formatting, storing only entered times, such as 9:30 AM. The SQL "startTime"
and "endTime" fields are SmallDateTime data types.
If I remove the StartTime and EndTime fields, there is no issue with adding
the records, of course. There is also no issue with the AttendanceDate field.
What do I need to do in order to get the SQL table to accept my Access time
values?