Better / faster solution for OptionButtons?

A

AMK4

I have a userForm with 5 OptionButtons within a Frame on it (there'
also a ComboBox on this userForm, which is irrelevant to this issue.)
In order to figure out which OptionButton was picked, I have thi
snippet of code
Code
-------------------
If targetForm1 = True Then
targetForm = 1
ElseIf targetForm2 = True Then
targetForm = 2
ElseIf targetForm3 = True Then
targetForm = 3
ElseIf targetForm4 = True Then
targetForm = 4
ElseIf targetFormCU = True Then
targetForm = 99
Else
errForm = True
End I
-------------------

There has got to be an easier, maybe faster way of settin
*targetForm*. please tell me there is. I can't imaging having man
OptionButtons and having to do this *If ... ElseIf ... Else ... End If
routine..
 
T

Tim Williams

If you're going to "bump" you might consider including the original text.
Many people use an actual newsreader and hide read messages, so all I'm
seeing is your bump.

Tim
 
A

AMK4

Sorry Tim, here's the original message:
I have a userForm with 5 OptionButtons within a Frame on it (there'
also a ComboBox on this userForm, which is irrelevant to this issue.)
In order to figure out which OptionButton was picked, I have thi
snippet of code:> Code
-------------------
targetForm = 1
ElseIf targetForm2 = True Then
targetForm = 2
ElseIf targetForm3 = True Then
targetForm = 3
ElseIf targetForm4 = True Then
targetForm = 4
ElseIf targetFormCU = True Then
targetForm = 99
Else
errForm = True
End I -------------------
There has got to be an easier, maybe faster way of settin
*targetForm*. please tell me there is. I can't imaging having man
OptionButtons and having to do this *If ... ElseIf ... Else ... En
If* routine..
 
T

Tim Williams

A bit more maintainable:

z = -1
For x = 1 To 4
If Me.Controls("targetForm" & x).Value = True Then
z = x
Exit For
End If
Next x
If z = -1 Then z = 99

Tim.
 

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