Hi,
I have a control array of 3 option buttons on my form. I want to hit a command button which pops up a msgbox and let's me know which option index is currently selected.
Thanks,
Dan
Printable View
Hi,
I have a control array of 3 option buttons on my form. I want to hit a command button which pops up a msgbox and let's me know which option index is currently selected.
Thanks,
Dan
Try this:
Code:Private Sub Command1_Click()
For i = 0 To 2
opt = Option1(i).Value
If opt = True Then opt = Option1(i).Index: Exit For
Next i
MsgBox "Option1(" & opt & ")"
End Sub
on the click event of your command button
suppose option1(0), option1(1), option1(2) are your option buttons
do something like
if option1(0).value = true then
msgbox "0"
else if option1(1).value = true then
msgbox "1"
etc...
This is the answer in its simplest form
I am guessing you're new to VB
Since only one option box may be selected at any one time:
CheersCode:Option Explicit
Dim opt as Integer
Private Sub Option1_Click(Index As Integer)
' saves the selected option button index to a module variable
opt = Index
End Sub
Private Sub Command1_Click()
MsgBox opt
End Sub