Code help needed for Option Buttons to control Subs
Hi Brian,
While in Design mode if you right click on the option button and select View
Code it will take you to the VBA editor for the forms and create a Sub / End
sub. I would put the code in there like the following instead of in another
module .
Note that If Me.OB_601 is the same as
If Me.OB_601 = True
Private Sub OB_601_Click()
If Me.OB_601 Then
'Your code here
End If
End Sub
Private Sub OB_602_Click()
If Me.OB_602 Then
'Your code here
End If
End Sub
Private Sub OB_603_Click()
If Me.OB_603 Then
'Your code here
End If
End Sub
However, you can call the code in a standard module if that is what you want
to do but you will still need a sub for each of the option buttons. Example
as follows.
Private Sub OB_601_Click()
If Me.OB_601 Then
Call String_01
End If
End Sub
You normally only put code in a separate module if the same code is being
used for all the options with only minor changes dependant on the particular
button. You would call the sub and pass the option button as a parameter.
Without seeing all of your code it is hard to advise if this is the better
way.
--
Regards,
OssieMac
"Brian" wrote:
I have a User form with (20) option buttons on it. It does what I want by
only being able to check 1 option button.
Option Button Names:
OB_601
OB_602 - OB_619
OB_620
What I need help with is when user checks the correct option button, that
button exicutes code located in a module.
Code in Module: There are (20) Subs named like below
Sub String_01()
Sub String_02() - Sub String_19()
Sub String_20()
I think the code for each Option button is something like this, because
there default position is False and they only show true when selected.
If OB_601 = True
then call Sub String_01()
If OB_602 = True
then call Sub String_02()
If OB_603 = True
then call Sub String_03()
Etc....
End Sub
|