Where condition in DoCmd.OpenReport (1 Viewer)

DJ44

Registered User.
Local time
Today, 04:22
Joined
May 19, 2003
Messages
29
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:
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

Wino Moderator
Staff member
Local time
Today, 04:22
Joined
Aug 30, 2003
Messages
36,125
Notice the single quotes you added when you got it to work by hand? Try this:

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

DJ44

Registered User.
Local time
Today, 04:22
Joined
May 19, 2003
Messages
29
Works great. Thanks for the help!
 

Users who are viewing this thread

Top Bottom