CommandButtons and OptionButtons on Userform
Hi Mike -
The problem stems from the fact that Excel handles the value of grouped
optionsbuttons differently than Access. In Access, the grouped option
buttons are automatically assigned an incremental value and the value of the
selected button is passed to the group (as its value). Excel doesn't do this
overhead bookkeeping for you. The only thing you get by grouping
optionbuttons in Excel is mutual exclusivity (can only select one of the
group). You have to manually evaluate the buttons to see which is selected.
Here is one approach to this evaluation demonstrated by modifying your
original code to branch properly in the Select Case statement.
Private Sub cmdPrint_Click()
Dim oBtn As Object
Dim strWhere As String
'strWhere = (DatePicker?)
On Error GoTo PrintPreviewError
i = 0
For Each oBtn In Me.Controls
If TypeName(oBtn) = "OptionButton" Then
If oBtn.Value = True Then i = i + 1: Exit For
End If
Next 'oBtn
Select Case i
Case 1
MsgBox "Option Button 1 selected"
' DoCmd.OpenReport "Payroll-Full Time", acViewPreview, , strWhere
' DoCmd.Maximize
Case 2
MsgBox "Option Button 2 selected"
' DoCmd.OpenReport "Payroll-Part-time", acViewPreview, , strWhere
' DoCmd.Maximize
Case Else
MsgBox "Select A Report!!!!!!!"
End Select
PPNormalExit:
Exit Sub
PrintPreviewError:
Resume PPNormalExit
Exit Sub
End Sub
--
Jay
"Mike" wrote:
Hello
I am having trouble with a Select Case Statement. I have about 6 reports
that I would like one command button to preveiw based on which Optionbutton
is
Selected. This is a code that I use in Access but not having any luck in
excel
can someone tell if this can been done and how
Thanks
Private Sub cmdPrint_Click()
Dim strWhere As String
'strWhere = (DatePicker?)
On Error GoTo PrintPreviewError
Select Case Me.ReportsGroup
Case 1
DoCmd.OpenReport "Payroll-Full Time", acViewPreview, , strWhere
DoCmd.Maximize
Case 2
DoCmd.OpenReport "Payroll-Part-time", acViewPreview, , strWhere
DoCmd.Maximize
Case Else
MsgBox "Select A Report!!!!!!!"
End Select
PPNormalExit:
Exit Sub
PrintPreviewError:
Resume PPNormalExit
Exit Sub
End Sub
|