Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Option Group Report VBA 2

Status
Not open for further replies.

kyjoey

Technical User
Jun 6, 2005
23
US
I think this is easy to do, but I am not sure how to write this. Here it is:

I have an option group on my form (5 choices) Each choice is for a report to print. I did it using macros, but the report goes behind the form. So, I need to write a snippet of code so that when the option is selected the code prints the report. I can do it using this piece:

Private Sub Command37_Click()
DoCmd.OpenReport "rptNAMCNotScheduled", acViewPreview
End Sub

However, the code will not work for each option, because it will keep generating the same report. I need it run the report associated with each option. If someone could help me with the sample code...I believe I can get the rest to work. Thanks everyone!!

-J

-Joey
 
Use a select case:

Private Sub Command37_Click()
select case [MyOptionGroup] 'enter option group name
case 1 'user selects option value 1
DoCmd.OpenReport "rptNAMCNotScheduled", acViewPreview
case 2
DoCmd.OpenReport "report2", acViewPreview
case 3
DoCmd.OpenReport "report3", acViewPreview
......
case else
msgbox "please select a report first"
end select

me.visible=false

End Sub

The case tells it to look at hte option group for a value, find the section that corresponds to that value and run the code in that section.

The me.visible=false hides the selection form so you can see the report - good if the form is opened as dialog (always on top)
 
Perfect! That nailed it! The only small issue with this, is when the report is generated the dialog form closes as well. Is there a way to keep the form open after closing the report so that the user can choose another report if needed?

This was a HUGE help!!! Thank you!!

-Joey
 
try it with an apostrophe (') before
me.visible =false

in SeeThru's code

Bob
 
Perfect! Thanks a bunch Bob!



-Joey
 
Personally what I like to do is put the report titles in a list box when I have several reports to choose from. Because there is a good chance you could have more reports to run, then you end up with option buttons everywhere.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top