Using 1 button to preview reports instead of 1 for each report

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with 20 reports on it. Currently there are also 20 preview buttons(1 for each report). Is it possible for me to create 1 button that will run all reports? I have a checkbox(in an option group) next to each report. So if the checkbox is checked the print button should print the checked report. How would i go about coding the button for this?

Thanks
 
An option group stores selections with an option number.
Make sure all your reports are in the group and keep track
of the option number for each. Then put this code behind
the one command button:

Private Sub cmdRunReport_Click()

Dim strReport As String

' Set the report name based on the report
' selected in the option group
Select Case optWhichReport
Case 1
strReport = "rptFirstReport"
Case 2
strReport = "rptSecondReport"
Case 3
strReport = "rptThirdReport"
Case Etc...
strReport = "rptRestOfTheReports..."
End Select

' open the report
DoCmd.OpenReport strReport, acViewPreview

End Sub

Hope this helps!

Howard Brody

-----Original Message-----
I have a form with 20 reports on it. Currently there are
also 20 preview buttons(1 for each report). Is it
possible for me to create 1 button that will run all
reports? I have a checkbox(in an option group) next to
each report. So if the checkbox is checked the print
button should print the checked report. How would i go
about coding the button for this?
 
Josh said:
I have a form with 20 reports on it. Currently there are also 20
preview buttons(1 for each report). Is it possible for me to create 1
button that will run all reports? I have a checkbox(in an option group)
next to each report. So if the checkbox is checked the print button
should print the checked report. How would i go about coding the button
for this?

Thanks

Using an Option Group is one way.
Code the Command Button's Click event:

Dim strReport as String
Select Case OptionGroupName
Case is = 1
strReport = "SomeReport"
Case is = 2
strReport = "Another Report"
etc.....

End Select

DoCmd.OpenReport strReport, acViewPreview

The difficulty with this approach is you are limited to the reports at
the time the event code is written. If a report is later added to (or
removed from) the database, you must re-write the Command Button event
code.

Another approach might be to use a ComboBox to list all the reports in
the database. Add a new one, and it automatically gets added.

As Combo Box RowSource:

SELECT MSysObjects.Name FROM MSysObjects WHERE (((Left([Name],1))<>"~")
AND ((MSysObjects.Type)=-32764)) ORDER BY MSysObjects.Name;

Then you would simply code the Combo Box AfterUpdate event:

DoCmd.OpenReport Me!ComboName, acViewPreview

and not bother with the command button.

It would certainly take up much less space than a 20 button option
group, and requires no additional maintenance.
 
Back
Top