Hi,
I have a form with a combo box on it. When a name from the combo box is selected I want to display the related records from a query in a report, however I am getting an error when running the code. The error states "Syntax error (missing operator) in query expression '[consultant]=Paul'."
The code looks like this:
*************************
Private Sub cmdPrint_Click()
Dim strInput As String
Dim db As Database
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim stLink As String
Dim strName As String
stDocName = "WeeklyJobs"
strName = cboConsultant.Column(0)
Set rs = New ADODB.Recordset
rs.ActiveConnection = CurrentProject.Connection
stLink = "[consultant]= " & strName
strSQL = "SELECT * FROM JobsBooked2 WHERE " & _
stLink
Set db = CurrentDb
rs.Open strSQL <----ERROR OCCURS HERE
DoCmd.OpenReport stDocName, acViewNormal, , stLink
DoCmd.Close acReport, stDocName
Set rs = Nothing
Set db = Nothing
End Sub
***********************************
The consultant field is just a text field
Regards,
- Paul
I have a form with a combo box on it. When a name from the combo box is selected I want to display the related records from a query in a report, however I am getting an error when running the code. The error states "Syntax error (missing operator) in query expression '[consultant]=Paul'."
The code looks like this:
*************************
Private Sub cmdPrint_Click()
Dim strInput As String
Dim db As Database
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim stLink As String
Dim strName As String
stDocName = "WeeklyJobs"
strName = cboConsultant.Column(0)
Set rs = New ADODB.Recordset
rs.ActiveConnection = CurrentProject.Connection
stLink = "[consultant]= " & strName
strSQL = "SELECT * FROM JobsBooked2 WHERE " & _
stLink
Set db = CurrentDb
rs.Open strSQL <----ERROR OCCURS HERE
DoCmd.OpenReport stDocName, acViewNormal, , stLink
DoCmd.Close acReport, stDocName
Set rs = Nothing
Set db = Nothing
End Sub
***********************************
The consultant field is just a text field
Regards,
- Paul