I have a form that provides my users with a summary of vacation time (Associate Summary). I also have a report that generates the summary information in report format for email and printing (Summary). Both work fine independently with the summary selecting the individual user based on a ComboBox, and the report pulles all users. I am looking for a way to place a command button on the Form (Associate Summary) to open and filter the report (Summary) to the user name that is currently displayed on the Form (Associate Summary). I have modified my form with a command button and added this code.
Private Sub Command22_Click()
DoCmd.OpenReport "Summary", acViewPreview, , "Name = " & Me.Combo8
End Sub
This worked with the exception of asking me to type in teh name for the report. Then it generated just as I want. I tried adjusting to a field that wasnt a combo box assuming that the multiple values associated with the combo box were the problem.
Private Sub Command22_Click()
DoCmd.OpenReport "Summary", acViewPreview, , "Name = " & Me.Text12
End Sub
Text12 is an expression joining two fields with a comma.
=[Last] & ", " & [First]
result... Doe, John
When I use the command button now I recieve a debug with the following error.
Run-Time error '3075':
Syntax error (comma) in query expression '(Name = Doe, John)'.
Thoughts…
Use the
OpenReportmethod’sWhereConditionparameter to filter the report’s record source.So, assuming the form has a text box named
txtUserNameand the report’s record source includes a field nameduser_name, use something like this in your command button’s click event procedure:Actually you can make troubleshooting easier by using a string variable to hold WhereCondition.