Using a filtering form to display reports (1 Viewer)

diversoln

Registered User.
Local time
Today, 12:04
Joined
Oct 8, 2001
Messages
119
I have a screen showing several report icons. It would be nice if many of these reports were filtered by month and year to limit the size of the reports to data of interest. What I'd like to do is have the user select the report icon, bring up a small form so he can choose the month and year, then run the query to filter the data for the report. I'm wondering if I can use the same Month_Year_Form for each of my reports (or am I forced to use a seperate Month_Year_Form for every report?

The problem I'm running into is when I run my program, using the code shown below that's initiated by selecting the desired report icon from my main reports menu, the program doesn't stop and wait for the form to be filled in. It simply brings up an "empty" report. How can I get the code to stop and wait for the user to press the "continue" button on the Month_Year_Form so that the query will have the parameters necessary to build the report appropriately?

I know I could do this if I had a seperate Month_Year_Form for each report since I could put the code to run the report from the "continue" button on my Month_Year_Form. But having all of these Month_Year_Forms would be inefficient. Is there a way I can set up a variable for the report I want to run based on the icon selected from the main reports screen and use the variable to run the report from the Month_Year_Form's continue button?


This is my current code: I'd like the code to stop and wait for the continue button to be selected on my Month_Year_Form, but it just keeps running....

Private Sub Discovery_Click()
On Error GoTo Err_Discovery_Click

Dim stDocName As String
Dim stDocName2 As String

stDocName = "Discovery Process"
stDocName2 = "Month_Year_Form"
DoCmd.OpenForm stDocName2
DoCmd.Maximize
DoCmd.OpenReport stDocName, acPreview
DoCmd.Maximize

Exit_Discovery_Click:
Exit Sub

Err_Discovery_Click:
MsgBox Err.Description
Resume Exit_Discovery_Click

End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:04
Joined
Aug 30, 2003
Messages
36,126
I do something like what you want I think. The code behind the button just opens the criteria form (your Month_Year_Form). It doesn't open the report. Included in the DoCmd.OpenForm is the name of the desired report in the OpenArgs argument. Then, in the continue button code in the criteria form, use OpenArgs in place of the report name. In other words, you're passing the name of the desired report in OpenArgs. That way the criteria form can be used for any report.
 

Users who are viewing this thread

Top Bottom