Needing help understanding the context behind the DoCmd.OpenReport function. I have a button on a form that generated a report with all of the records in my database tables. I want the report to only generate based on the information displayed in the Form. I have used the wizard to add a command button to my form to generate the summary report and here is the automated VBA.
Private Sub GenRpt_Click()
On Error GoTo Err_GenRpt_Click
Dim stDocName As String
Dim FrmId As String
stDocName = "Summary v2"
DoCmd.OpenReport stDocName, acPreview
Exit_GenRpt_Click:
Exit Sub
Err_GenRpt_Click:
MsgBox Err.Description
Resume Exit_GenRpt_Click
End Sub
I know that I am suppoed to insert soime kind of conditional staement into the code just after the DoCmd.OpenReport, but cant figure out how to pass the userid from the form to filter the report. My form has a text box “Text31” that contains a UserID, my report has a text box “tstUserID” that corresponds to the results. How do I limit the report results to only the userid displayed in “Text31” before my cmd button click?
Something like*:
Where UserID is the name of a numeric field included in the record source of the report.
If the field is a text data type, you will need quotes:
It does not seem likely that the userID will include an internal quote mark, so the above should be safe enough, if it was likely, you would need to escape like so:
You are adding a WHERE condition, and it takes a very similar form to the WHERE statement in a query.
*The Syntax for Openreport is given as: