+ Reply to Thread
Results 1 to 7 of 7

Setting ToggleButton Value

  1. #1
    Registered User
    Join Date
    01-17-2006
    Posts
    14

    Setting ToggleButton Value

    Is there a way to set the value of a toggle button without triggering a click event? I have a set of three buttons that I want to deselect the other two options when any one is selected.

    ie.
    Private Sub ToggleButton1_Click()
    ToggleButton1.Value = True
    ToggleButton2.Value = False
    ToggleButton3.Value = False
    End Sub

    When I set the value of the other two it seems to trigger a click event on them as well.

    I have tried the example of exclusive toggle buttons on ms site (http://support.microsoft.com/?kbid=213714) but couldn't get it to work. It seemed to save all the calls to the sub until I closed the form.
    Last edited by fazstp; 01-31-2006 at 09:38 PM.

  2. #2
    Dave Peterson
    Guest

    Re: Setting ToggleButton Value

    You can add a public variable, set it to something, check it and then have each
    _click event check that variable:

    Dim blkProc as boolean

    Private Sub ToggleButton1_Click()
    blkproc = true
    ToggleButton2.Value = False
    ToggleButton3.Value = False
    blkproc = false
    End Sub

    Private Sub ToggleButton2_Click()
    if blkproc = false then exit sub
    'existing code here
    End Sub

    I'm not quite sure why you would be setting button1 to true in the
    togglebutton1_click event, though.

    fazstp wrote:
    >
    > Is there a way to set the value of a toggle button without triggering a
    > click event? I have a set of three buttons that I want to deselect the
    > other two options when any one is selected.
    >
    > ie.
    > Private Sub ToggleButton1_Click()
    > ToggleButton1.Value = True
    > ToggleButton2.Value = False
    > ToggleButton3.Value = False
    > End Sub
    >
    > When I set the value of the other two it seems to trigger a click event
    > on them as well.
    >
    > I have tried the example of exclusive toggle buttons on ms site
    > (http://support.microsoft.com/?kbid=213714) but couldn't get it to
    > work. It seemed to save all the calls to the sub until I closed the
    > form.
    >
    > --
    > fazstp
    > ------------------------------------------------------------------------
    > fazstp's Profile: http://www.excelforum.com/member.php...o&userid=30574
    > View this thread: http://www.excelforum.com/showthread...hreadid=507025


    --

    Dave Peterson

  3. #3
    Registered User
    Join Date
    01-17-2006
    Posts
    14

    Cool

    Thanks for that. That did the trick. The reason for setting the state of the clicked button to True is so that there is always at least one button selected, otherwise clicking the already selected option leaves all buttons deselected.

  4. #4
    Tom Ogilvy
    Guest

    Re: Setting ToggleButton Value

    Most people use optionbuttons for this effect. Users are used to that
    paradigm.

    --
    Regards,
    Tom Ogilvy


    "fazstp" <fazstp.22j3rn_1138760750.4557@excelforum-nospam.com> wrote in
    message news:fazstp.22j3rn_1138760750.4557@excelforum-nospam.com...
    >
    > Thanks for that. That did the trick. The reason for setting the state of
    > the clicked button to True is so that there is always at least one
    > button selected, otherwise clicking the already selected option leaves
    > all buttons deselected.
    >
    >
    > --
    > fazstp
    > ------------------------------------------------------------------------
    > fazstp's Profile:

    http://www.excelforum.com/member.php...o&userid=30574
    > View this thread: http://www.excelforum.com/showthread...hreadid=507025
    >




  5. #5
    Registered User
    Join Date
    01-17-2006
    Posts
    14

    Re optionbuttons

    Can you have two groups of three optionbuttons on one form (ie. selecting one of three options for two different variables)?

  6. #6
    Tom Ogilvy
    Guest

    Re: Setting ToggleButton Value

    Sure. One property of an ActiveX (control toolbox toolbar) optionbutton is
    the groupname.

    Pick any name and assign it to each of the first three (first group). Pick
    any other name and assign it to each of the next three.

    You can also put two frames on the Userform, then put 3 optionbuttons in
    each.

    --
    Regards,
    Tom Ogilvy



    "fazstp" <fazstp.22j5un_1138763402.1073@excelforum-nospam.com> wrote in
    message news:fazstp.22j5un_1138763402.1073@excelforum-nospam.com...
    >
    > Can you have two groups of three optionbuttons on one form (ie.
    > selecting one of three options for two different variables)?
    >
    >
    > --
    > fazstp
    > ------------------------------------------------------------------------
    > fazstp's Profile:

    http://www.excelforum.com/member.php...o&userid=30574
    > View this thread: http://www.excelforum.com/showthread...hreadid=507025
    >




  7. #7
    Registered User
    Join Date
    01-17-2006
    Posts
    14

    Cool

    Ah, thanks Tom. No sense re-programming the wheel.

+ 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