Option Box Question

  • Thread starter Thread starter ljg08
  • Start date Start date
L

ljg08

Hey.,...can anyone tell me why this code does not work, I am missing
something really simple ?

Private Sub cmdrun01_Click()
If Me.Option38 = True Then
DoCmd.OpenReport "qryMainreport01", acViewPreview
Else
End If
If Me.Option40 = True Then
DoCmd.OpenQuery "qryMainreport", acViewNormal
Else
End If
If Me.Option42 = True Then
DoCmd.OpenQuery "qryMainreport", acViewNormal
Else
End If

End Sub
 
I assume the 3 option buttons you describe belong to an option group. You
don't address them directly. You address the value of the option group.
Each Option in a group has an Option Value property that is an integer the
option group control returns when that option is the one currently selected.
The best way to do this is with a Select Case statement:

Dim strRptName As String

Select Case Me.MyOptionGroup
Case 1
DoCmd.OpenReport "qryMainreport01", acViewPreview
Case 2
DoCmd.OpenQuery "qryMainreport", acViewNormal
Case 3
DoCmd.OpenQuery "qryMainreport", acViewNormal
End Select
 
Cheers Dave,

Thats sorted it.

Regards

Klatuu said:
I assume the 3 option buttons you describe belong to an option group. You
don't address them directly. You address the value of the option group.
Each Option in a group has an Option Value property that is an integer the
option group control returns when that option is the one currently
selected.
The best way to do this is with a Select Case statement:

Dim strRptName As String

Select Case Me.MyOptionGroup
Case 1
DoCmd.OpenReport "qryMainreport01", acViewPreview
Case 2
DoCmd.OpenQuery "qryMainreport", acViewNormal
Case 3
DoCmd.OpenQuery "qryMainreport", acViewNormal
End Select
 
Back
Top