I have a form with 12 option buttons with code behind each one. OB 7 unhides checkbox1.
When another option button is selected checkbox1 should be hidden. Is there a better way other than adding code to hide the checkbox to each option button?
Option Buttons
-
- GoldLounger
- Posts: 2618
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Option Buttons
Regards,
John
John
-
- Administrator
- Posts: 78241
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Option Buttons
You could create a single procedure in the userform module that hides the check box, and call that from each of the option buttons except #7.
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2618
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Re: Option Buttons
Hans,
Your suggestion makes sense but is that not the same as adding this bit of code behind each option button: UserForm1.CheckBox1.Visible = False?
Your suggestion makes sense but is that not the same as adding this bit of code behind each option button: UserForm1.CheckBox1.Visible = False?
Regards,
John
John
-
- Administrator
- Posts: 78241
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Option Buttons
More or less, yes, except that if you wanted to change the name of the check box, you'd have to change it only in the single procedure instead of in the 11 On Click event procedures of the option buttons.
An alternative would be to create a custom option button in a class module, but that would be overkill, since it would require extra code in the Userform_Initialize event procedure.
An alternative would be to create a custom option button in a class module, but that would be overkill, since it would require extra code in the Userform_Initialize event procedure.
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2618
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
-
- 4StarLounger
- Posts: 536
- Joined: 27 Jun 2021, 10:46
Re: Option Buttons
It is a shame that VBA (or more specifically MS Forms), unlike classic VB6, does not support control arrays, which make this kind of thing easy.
-
- Administrator
- Posts: 78241
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands