I have a form showing some customer data. The form is based on a query. On the form there is a combo box and the user can select different courses. My goal is to select a course from the combo and when press a command button, to filter the results on the form.
Here is my code attached to the OnClick event of the command button:
Private Sub ProcessButton_Click()
Dim db As Database
Dim qr As QueryDef
Set db = CurrentDb
Set qr = db.QueryDefs("WhoTook")
Me.Form.RecordSource = "SELECT * FROM WhoTook WHERE CourseName = " & [Forms]![Tools].[SelectCourse]
When running the above code I am getting syntax error (missing operator in query expression CourseName = ...
I just can't figure out what's wrong. You guys are much sharper then me...
The syntax error disapeared, however this seems to be only one of many problems. When running the code with any selection of the combo, the form becomes blank - meaning no controls are visible (probably because the query does not return any results, so the record source is empty, but it shoud not - there are plenty of records available for the specific WERE condition).
It must be a simple task - to filter the record source by one or many parameters. What am I doing wrong?