S
scott
I'm having problems with syntax in a RunSQL statement in PROBLEM PART below.
I get an "incorrect syntax near ':'" and the VBE highlights the RunSQL part.
That's strange since there's no colon in my RunSQL part. It's probably just
missing a quote, but I can't see it.
I posted full code to be safe, but it works fine without the "RunSQL" part.
PROBLEM PART:
DoCmd.RunSQL "INSERT INTO t_data (field1, field2" & _
", field3, field4, field5) VALUES (" & objRS![field1] & ", " &
objRS![field2] & _
", " & Trim(objRS!field3) & ", " & Trim(objRS!field4) & _
", " & Trim(objRS!field5) & ")"
FULL CODE:
Dim objConn As ADODB.Connection
Dim objRS As ADODB.Recordset
Dim sPath As String, sFile As String, sSQL As String
Set objConn = New ADODB.Connection
Set objRS = New ADODB.Recordset
sPath = "C:\databases\"
sFile = "myDBasefile.DBF"
sSQL = "SELECT [Date], [Time], transType, tagName, alarmType FROM
myDBasefile"
objConn.Open "Driver={Microsoft dBASE Driver (*.dbf)};" & _
"DriverID=277;" & _
"Dbq=" & sPath '"Dbq=c:\somepath"
objRS.Open sSQL, objConn, , , adCmdText
Do While Not objRS.BOF And Not objRS.EOF
DoCmd.RunSQL "INSERT INTO mydataTable (field1, field2" & _
", field3, field4, field5) VALUES (" & objRS![field1] & ", " &
objRS![field2] & _
", " & Trim(objRS!field3) & ", " & Trim(objRS!field4) & _
", " & Trim(objRS!field5) & ")"
'Debug.Print objRS.GetString
Loop
I get an "incorrect syntax near ':'" and the VBE highlights the RunSQL part.
That's strange since there's no colon in my RunSQL part. It's probably just
missing a quote, but I can't see it.
I posted full code to be safe, but it works fine without the "RunSQL" part.
PROBLEM PART:
DoCmd.RunSQL "INSERT INTO t_data (field1, field2" & _
", field3, field4, field5) VALUES (" & objRS![field1] & ", " &
objRS![field2] & _
", " & Trim(objRS!field3) & ", " & Trim(objRS!field4) & _
", " & Trim(objRS!field5) & ")"
FULL CODE:
Dim objConn As ADODB.Connection
Dim objRS As ADODB.Recordset
Dim sPath As String, sFile As String, sSQL As String
Set objConn = New ADODB.Connection
Set objRS = New ADODB.Recordset
sPath = "C:\databases\"
sFile = "myDBasefile.DBF"
sSQL = "SELECT [Date], [Time], transType, tagName, alarmType FROM
myDBasefile"
objConn.Open "Driver={Microsoft dBASE Driver (*.dbf)};" & _
"DriverID=277;" & _
"Dbq=" & sPath '"Dbq=c:\somepath"
objRS.Open sSQL, objConn, , , adCmdText
Do While Not objRS.BOF And Not objRS.EOF
DoCmd.RunSQL "INSERT INTO mydataTable (field1, field2" & _
", field3, field4, field5) VALUES (" & objRS![field1] & ", " &
objRS![field2] & _
", " & Trim(objRS!field3) & ", " & Trim(objRS!field4) & _
", " & Trim(objRS!field5) & ")"
'Debug.Print objRS.GetString
Loop