Microsoft Office Tutorials and References
In Depth Information
OptionButtons
figurE 19-11
Figure 19-11 shows that the month of August was selected, and in real practice, you’d identify that
selection in your code with a variable that refers to the selected month name, and produces the
report for that month. One way to do that is to loop through each of the OptionButtons and stop
when you encounter the selected OptionButton whose value would be True.
To help make the point, there is a button on the form with the caption “ID Selected Option,”
and when you click the button, a Message Box appears, telling you the name of the selected
OptionButton and its caption. The following code examines the OptionButtons’ status and then
produces the Message Box:
Private Sub CommandButton1_Click()
Dim intOption As Integer, optName As String, optCaption As String
For intOption = 1 To 12
If Controls(“OptionButton” & intOption) = True Then
optName = Controls(“OptionButton” & intOption).Name
optCaption = Controls(“OptionButton” & intOption).Caption
MsgBox _
“Name: “ & optName & vbCrLf & _
“Caption: “ & optCaption, , _
“Info about the OptionButton you selected:”
Exit For
End If
Next intOption
End Sub
Search JabSto ::




Custom Search