Printing From Option Groups

J

John

Hi,
I have several options buttons in an option group which each relate to a
report.
If a report is selected how do I set a single command button on a form to
print the option selected.

Regards

John
 
F

fredg

Hi,
I have several options buttons in an option group which each relate to a
report.
If a report is selected how do I set a single command button on a form to
print the option selected.

Regards

John

Just a few options (let's say 3)? Code a command button's Click
event:

If Not IsNull(OptionGroupName) Then
If Me.OptionGroupName = 1 Then
Docmd.OpenReport "ReportA", acViewPreview
ElseIf Me.OptionGroupName = 2 Then
Docmd.OpenReport "ReportB", acViewPreview
Else
Docmd.OpenReport "ReportC", acViewPreview
End If
Else
MsgBox "No report selected"
End if

If you had many choices, you could use the Select Case statement.
Look it up in VBA help.
 
J

John

Fredg
Thanks for the reply.
I was looking at the VBA section for the SelectCase method as I have 15
reports to choose from.
I'm sorry to say I did not accomplish my task.
I could not find a section which directly relates to my question.
Any help please on the selectcase method would be most helpful.

I have 15 optionboxes Option Values of 1-15 and named Option1 - Option15 in
an option group called PrintReports
A command button named cmdPrintReport

Regards

John
 
F

fredg

Fredg
Thanks for the reply.
I was looking at the VBA section for the SelectCase method as I have 15
reports to choose from.
I'm sorry to say I did not accomplish my task.
I could not find a section which directly relates to my question.
Any help please on the selectcase method would be most helpful.

I have 15 optionboxes Option Values of 1-15 and named Option1 - Option15 in
an option group called PrintReports
A command button named cmdPrintReport

Regards

John


Code the command button Click event like this:
Dim strReport as String
Select Case Me![PrintReports]
Case 1
strReport = "ReportA"
Case 2
strReport = "ReportB"
Case 3
strReport = "ReportC"
etc...
Case 15
strReport = ReportWhatever"
Case Else
strReport = ""
End Select
If strReport = "" then
MsgBox "No report was selected."
Else
Docmd.OpenReport strReport, ACViewPreview
End If
 
J

John

Many Thanks
That works a treat.

Keep up the good work guys.

Kindest Regards

John


fredg said:
Fredg
Thanks for the reply.
I was looking at the VBA section for the SelectCase method as I have 15
reports to choose from.
I'm sorry to say I did not accomplish my task.
I could not find a section which directly relates to my question.
Any help please on the selectcase method would be most helpful.

I have 15 optionboxes Option Values of 1-15 and named Option1 - Option15
in
an option group called PrintReports
A command button named cmdPrintReport

Regards

John


Code the command button Click event like this:
Dim strReport as String
Select Case Me![PrintReports]
Case 1
strReport = "ReportA"
Case 2
strReport = "ReportB"
Case 3
strReport = "ReportC"
etc...
Case 15
strReport = ReportWhatever"
Case Else
strReport = ""
End Select
If strReport = "" then
MsgBox "No report was selected."
Else
Docmd.OpenReport strReport, ACViewPreview
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top