Full Version: Report Opened From A Form Event
UtterAccess Discussion Forums > Microsoft® Access > Access Reports
punster
I have a report that is based on a query. The data in the query is used to determine exactly which fields from the query print on the Report. The criteria for the query is a value from a text box on a form in the database. If I open/run the report directly from the Report Object, it prompts me for the value of the text box, and then prints the data correctly. However, if I print the report from the form using "stDocName = "rptPrintCRQuote"; followed by "DoCmd.OpenReport stDocName, acNormal, I do not get all the fields correctly. I have tried putting my code on the Load, Activate, and Current Events - all of which seem to be fine when opening report directly, but when called from the DoCmd the code does not seem to be executed and I can't seem to use the debugger to see why not. Wondering if there is a different Event that I need to have my code on or why this only works when running the report dierectly? Any hints or suggestions would be very much appreciated.

fkegley
What you need to do is modify the query so that it gets the value directly from the text box on the form.

In the appropriate column, in one of the Criteria cells, put this:

[Forms]![NameOfForm]![NameOfTextBox]

The reason it works when you run the report directly is that you are essentially bypassing the form completely. Access does not even "know" the form is open, it is just accepting a value for a field rather than the value of a control on a form.

Oh, yeah, place a command button on the form that opens the report. Put the code to open the report in the click event of the command button.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.