Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Would this code work or do I need to have 20 seperate subs like the one you
showed me? Private Sub OB_601-620_Click() If Me.OB_601 Then Call String_01 End If If Me.OB_602 Then Call String_02 End If If Me.OB_603 Then Call String_03 End If If Me.OB_604 Then Call String_04 End If End Sub Thanks for your help "OssieMac" wrote: 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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Brian,
I don't know of any way of grouping the code into one sub. You will need separate subs for each button. I have often thought that there should be an event to detect a change in the group status and a Target parameter to identify the button that is True. -- Regards, OssieMac "Brian" wrote: Would this code work or do I need to have 20 seperate subs like the one you showed me? Private Sub OB_601-620_Click() If Me.OB_601 Then Call String_01 End If If Me.OB_602 Then Call String_02 End If If Me.OB_603 Then Call String_03 End If If Me.OB_604 Then Call String_04 End If End Sub Thanks for your help "OssieMac" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Enabling Option Buttons - Control | Excel Programming | |||
Worksheets and Control Option Buttons | Excel Worksheet Functions | |||
No control for option buttons, invisible macro?? | Excel Programming | |||
Selective control of Option Buttons | Excel Programming | |||
Control Box Option Buttons | Excel Programming |