I've got a user form to run a code depending on what kind of data I need to upload:
Basically, it has two radio buttons, IFT and MMAS, a ComboBox with two options, Public and Private. If an option Private is selected then another combination of radio buttons is activated: tier 1 and tier 2. And there is a checkbox Wipe out Formatting.
I need to make sure that a user first select one of the first radio buttons and an option from the combobox. If they select Private, they have to select tier 1 or tier 2 radio button. The last checkbox should be always selected. I use it for debugging the model. If a required option is not selected, then there should be a message like "Please select a template", and "Please select a datatype" and "Please select a tier". I have found the way to check all the controls but it also checks the inactivated ones. Also I can check individual controls with something like this:
But I cannot figure out how to make it to check only the required controls.
VBA Code:
Private Sub UserForm_Initialize()
'Reset the form
radiotempl1.Value = False
radiotempl2.Value = False
datatype.Clear
With datatype
.AddItem "Public"
.AddItem "Private"
End With
radiotier1.Value = False
radiotier2.Value = False
radiotier1.Enabled = False
radiotier2.Enabled = False
wipe_format.Value = True
End Sub
Basically, it has two radio buttons, IFT and MMAS, a ComboBox with two options, Public and Private. If an option Private is selected then another combination of radio buttons is activated: tier 1 and tier 2. And there is a checkbox Wipe out Formatting.
I need to make sure that a user first select one of the first radio buttons and an option from the combobox. If they select Private, they have to select tier 1 or tier 2 radio button. The last checkbox should be always selected. I use it for debugging the model. If a required option is not selected, then there should be a message like "Please select a template", and "Please select a datatype" and "Please select a tier". I have found the way to check all the controls but it also checks the inactivated ones. Also I can check individual controls with something like this:
VBA Code:
Private Sub modelrun_btn_Click()
Dim x As Long
x = 0
For Each xControl In frame_template.Controls
If TypeName(xControl) = "OptionButton" Then
If xControl.Value = True Then x = x + 1
End If
Next xControl
If x = 0 Then MsgBox "You must select a template"
UploadData
End Sub
But I cannot figure out how to make it to check only the required controls.