vendredi 25 novembre 2016

Only allowing one checkbox to be checked for a userform

So I'm making a userform and I have to use make a group of mutually exclusive checkboxes or only allow the user to pick one. "But just use option buttons!" you cry. Two problems with that:

  1. I already have a separate set of option buttons in the userform (I believe you can somehow group them to allow multiple sets but I am unfamiliar with how to actually do this).

  2. My professor specifically wants checkboxes

so I attempted to solve this problem like this

If CheckBoxBar.Value = True And CheckBoxatm.Value = True Then
GoTo Here:
End If

If CheckBoxatm.Value = True And CheckBoxmmHg.Value = True Then
GoTo Here:
End If

If CheckBoxatm.Value = True And CheckBoxpsia.Value = True Then
GoTo Here:
End If

If CheckBoxBar.Value = True And CheckBoxmmHg.Value = True Then
GoTo Here:
End If

If CheckBoxBar.Value = True And CheckBoxpsia.Value = True Then
GoTo Here:
End If

If CheckBoxmmHg.Value = True And CheckBoxpsia.Value = True Then
GoTo Here:
End If

The here leads to a message box that re initializes the userform after the msg box says "You are only allowed to select one" with code like this

Here: MsgBox "You are only allowed to select on pressure unit."

The code "works" but it always goes to the Here: statement despite only picking one of the checkboxes. Can you spot anything wrong?

Thanks for the help!




Aucun commentaire:

Enregistrer un commentaire