+ Reply to Thread
Results 1 to 6 of 6

Userform with Checkboxes

  1. #1
    Greg B
    Guest

    Userform with Checkboxes

    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

  2. #2
    Dave Peterson
    Guest

    Re: Userform with Checkboxes

    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.


    Greg B wrote:
    >
    > 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


    --

    Dave Peterson

  3. #3
    Bob Phillips
    Guest

    Re: Userform with Checkboxes

    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)


    "Greg B" <[email protected]> wrote in message
    news:[email protected]...
    > 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




  4. #4
    Chip Pearson
    Guest

    Re: Userform with Checkboxes

    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


    "Greg B" <[email protected]> wrote in message
    news:[email protected]...
    > 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




  5. #5
    Dave Peterson
    Guest

    Re: Userform with Checkboxes

    Or just use one checkbox and change the label:

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

    Greg B wrote:
    >
    > 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


    --

    Dave Peterson

  6. #6
    Greg B
    Guest

    Re: Userform with Checkboxes

    Bob Phillips wrote:
    > 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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1