option group to select report when button clicked

D

deb

I have an option group called grpPM on a form. The option group has 3
choices opt1, opt2, opt3)
I also have a report buttons(btnSales). Below is the code behind the button.
I would like to be able to revise the code, and when one of the opt group is
selected the corresponding report is opened.

How can I revise the below to make it work.

Private Sub Command41_Click()
On Error GoTo Err_Command41_Click

Dim stDocName As String
if opt1 is chosen then
stDocName = "rSalesMaster"
if opt2 is chosen then
stDocName = "rAreaMaster"
if opt3 is chosen then
stDocName = "rCombinedMaster"

DoCmd.OpenReport stDocName, acPreview

Exit_Command41_Click:
Exit Sub

Err_Command41_Click:
MsgBox Err.Description
Resume Exit_Command41_Click
 
K

Klatuu

Perfect opportunity to learn about the Select Case statement. I will assume
the option values are are 1, 2, and 3 respectively for the option buttons.
You do not query the value of an option button directly. Each button has an
option value. the Option Group control will return the value set in the
Option Value property of the currently selected button.

Private Sub Command41_Click()
Dim stDocName As String

On Error GoTo Err_Command41_Click

Select Case Me.grpPM
Case Is 1
stDocName = "rSalesMaster"
Case Is 2
stDocName = "rAreaMaster"
Case Is 3
stDocName = "rCombinedMaster"
End Select

DoCmd.OpenReport stDocName, acPreview

Exit_Command41_Click:
Exit Sub

Err_Command41_Click:
MsgBox Err.Description
Resume Exit_Command41_Click
End Sub
 

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