Userform with Checkboxes

G

Greg B

Hi all,

I have a userform where I use checkboxes for the person to select either
one or the other.

I need help with a macro to check if either of checkbox1 or checkbox2
has been selected, but to also check that they both haven't been
selected at the same time.

How can I do this?

Thanks
Greg
 
D

Dave Peterson

You could do that, but why not just use a couple of option buttons--then when
you choose one, the other is unchosen.

if me.checkbox1.value = true _
and me.checkbox2.value = true then
msgbox "not both!
exit sub '???
end if

might be one way to validate in your "ok" button.
 
B

Bob Phillips

Greg,

A perfect case for optionbuttons. When one is set, the other unsets. Code
like

With Me
If Optionbutton1 Then
'do button1 stuff
Else
'do button 2 stuff
End If
End WIth

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
C

Chip Pearson

If you only want one option to be selected, but not both, you
might use Option Button controls instead of check boxes -- they
designed for just this purpose.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
D

Dave Peterson

Or just use one checkbox and change the label:

Check this for Option A--leave unchecked for option B.
 
G

Greg B

Bob said:
Greg,

A perfect case for optionbuttons. When one is set, the other unsets. Code
like

With Me
If Optionbutton1 Then
'do button1 stuff
Else
'do button 2 stuff
End If
End WIth
Thanks for the help, I never even considered that option

Thanks

Greg
 
Top