![]() |
ADODB SQL help
Can anyone here tell me what is wrong with my SQL statement? I get a error of
Expected 1. Sub UpdateData2() On Error GoTo ErrorHandler Dim MyCn As ADODB.Connection Dim rst As ADODB.Recordset Dim strSQL As String Set MyCn = New ADODB.Connection ' Replace actual Access file path here MyCn.Open "DRIVER={Microsoft Access Driver (*.mdb)};" _ & "DBQ=G:\TestCQA.mdb" Set rst = New ADODB.Recordset strSQL = "SELECT * FROM tblExcel" _ & " WHERE tblExcel.TestID = " & Range("A2").Value rst.Open strSQL, MyCn If rst!IsReviewed = False Then 'no edit statement here? rst!IsReviewed = True rst.Update End If MyCn.Close ErrorHandler_Exit: Set MyCn = Nothing Exit Sub ErrorHandler: MsgBox Err.Description GoTo ErrorHandler_Exit End Sub |
ADODB SQL help
You may need to put single quotes around the Range.Value if its text
ie, " WHERE tblExcel.TestID = '" & Range("A2").Value & "'" either that or tblExcel.TestID doesn't exist Eric wrote: Can anyone here tell me what is wrong with my SQL statement? I get a error of Expected 1. Sub UpdateData2() On Error GoTo ErrorHandler Dim MyCn As ADODB.Connection Dim rst As ADODB.Recordset Dim strSQL As String Set MyCn = New ADODB.Connection ' Replace actual Access file path here MyCn.Open "DRIVER={Microsoft Access Driver (*.mdb)};" _ & "DBQ=G:\TestCQA.mdb" Set rst = New ADODB.Recordset strSQL = "SELECT * FROM tblExcel" _ & " WHERE tblExcel.TestID = " & Range("A2").Value rst.Open strSQL, MyCn If rst!IsReviewed = False Then 'no edit statement here? rst!IsReviewed = True rst.Update End If MyCn.Close ErrorHandler_Exit: Set MyCn = Nothing Exit Sub ErrorHandler: MsgBox Err.Description GoTo ErrorHandler_Exit End Sub |
All times are GMT +1. The time now is 10:37 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com