View Full Version : Where condition in DoCmd.OpenReport


DJ44
04-27-2005, 04:23 PM
Good Day.

I have search the forums but have not found an answer to my problem (or at least didn't recognize the answer)...

I would like to open a report using a cmdButton on a forum. The report is based on a query. I would like to filter the results of the query based on a field in the query, that I acquire from a txtBox in the form.

My code:


Private Sub cmdPrintBrief_Click()

Dim sWorkUnit As String
Dim sReportName As String

sReportName = "rptPriorities"
sWorkUnit = Me.tbxWorkUnit

DoCmd.OpenReport sReportName, acViewPreview, , "WorkUnit=" & sWorkUnit

End Sub

I recieve and error (missing operator).

I am not sure if my syntax is incorrect ..... do I have to set any properties in the report???? I ran into a similar problem when I was trying to open a form and worked around it by typing in the Where line with the actual name of the workunit "WorkUnit = 'MainStreet'"

All help is appreciated.

DJ

pbaldy
04-27-2005, 04:27 PM
Notice the single quotes you added when you got it to work by hand? Try this:

DoCmd.OpenReport sReportName, acViewPreview, , "WorkUnit='" & sWorkUnit & "'"

DJ44
04-27-2005, 05:05 PM
Works great. Thanks for the help!