I have the following piece of code behind a combobox on a form in Access 2003:
Dim RS As ADODB.Recordset
Set RS = New ADODB.Recordset
RS.Open "SELECT field1, field2, FROM table1 " & _
"WHERE field1 =" & Me.combo1, _
Application.CodeProject.Connection, adOpenStatic, adLockOptimistic, adCmdText
MsgBox RS("field1")
The combo box list contains text values and the code is situated behind the on click event. When a selection is made from the list the following error is returned:
Run-Time error '2147217900(8004e14)':
Syntax error (missing operator) in query expression 'field1 = combo1 selected value'.
If I replace Me.combo1 with a value from the list i.e. "WHERE field1 = 'John'" the code works. I am assuming there is some sort of setting behind the combobox that needs adjusting.
Thanks
C