using an if statement in a command button?

J

Jon M.

Okay here we go, I have a form with 3 radio buttons on it, each one is an
office location. I have 3 reports, each uses a different letterhead for the
3 offices. Can I create a single command button to run the appropriate
report based on which radio button is selected? I'm really not sure if there
is some code I can use on the command button or if what I need to do is
better suited in a query with an if statement or what. As always I
apprecaite any help I can get. Thanks.
 
F

fredg

Okay here we go, I have a form with 3 radio buttons on it, each one is an
office location. I have 3 reports, each uses a different letterhead for the
3 offices. Can I create a single command button to run the appropriate
report based on which radio button is selected? I'm really not sure if there
is some code I can use on the command button or if what I need to do is
better suited in a query with an if statement or what. As always I
apprecaite any help I can get. Thanks.

Code the command button's Click event:

Dim strReport as String

If IsNull(Me![OptionGroupName]) Then
MsgBox "You must select a location."
Exit Sub
End If

Select Case Me![OptionGroupName]
Case is = 1
strReport = "Location1Report"
Case is = 2
strReport = "Location2Report"
Case Else
strReport = "Loaction3Report"
End Select
DoCmd.OpenReport strReport, acViewPreview
 
J

Jon M.

Thank you sir, you are a gentleman and a scholar.
--
Jon M.


fredg said:
Okay here we go, I have a form with 3 radio buttons on it, each one is an
office location. I have 3 reports, each uses a different letterhead for the
3 offices. Can I create a single command button to run the appropriate
report based on which radio button is selected? I'm really not sure if there
is some code I can use on the command button or if what I need to do is
better suited in a query with an if statement or what. As always I
apprecaite any help I can get. Thanks.

Code the command button's Click event:

Dim strReport as String

If IsNull(Me![OptionGroupName]) Then
MsgBox "You must select a location."
Exit Sub
End If

Select Case Me![OptionGroupName]
Case is = 1
strReport = "Location1Report"
Case is = 2
strReport = "Location2Report"
Case Else
strReport = "Loaction3Report"
End Select
DoCmd.OpenReport strReport, acViewPreview
 

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