+ Reply to Thread
Results 1 to 10 of 10

Togglebuttons - Changing state based on state of the others

  1. #1
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Togglebuttons - Changing state based on state of the others

    Hi all,

    I am looking for some guidance on how to use toggle buttons effectively. Perhaps what I want to do can't be done with toggle buttons, or there may be a more appropriate control to use.

    I currently have 3 toggle buttons. At any one given time, only one can be in a TRUE state. So, when the user presses one button setting it to true, the other remaining two must be put in a FALSE state.

    Please Login or Register  to view this content.
    This is what I started with. It caused catastrophic problems, putting Excel into an unrecoverable crash. I think it was put into an eternal loop with each change in toggle state changing the toggle state of the others and so on.

    Can anyone suggest a way to effectively toggle the values of these controls in their different combinations.

    My userform initializes these as:

    Please Login or Register  to view this content.
    I have used mbevents coding to suppress control events during userform initialization in the past. The state of mbevents at the start of the initialization is false, meaning any control changes are executed during initialization. When mbevents = true, the current control change is suppressed with 'if mbevents then exit sub'

    I'm not sure if this the approach or not, as I have yet to make it effectively work with my trials.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Togglebuttons - Changing state based on state of the others

    Which controls are you using? If you use option buttons this is done automatically.

  3. #3
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Togglebuttons - Changing state based on state of the others

    Hi Stephen ... I was using a series of toggles buttons. I had thought about using the option buttons, but find that I am bound to their size (can't adjust them). Trivial, but they don't suit the userform as well as the buttons do.
    I'll look into how they work. If I have no other choice, then this is likely the route I'll have to go.

    Thanks for your suggestion!

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Togglebuttons - Changing state based on state of the others

    Don't think I've ever even noticed toggle buttons before! Does this do what you want?
    Please Login or Register  to view this content.

  5. #5
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Togglebuttons - Changing state based on state of the others

    You could give this a try:-
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Togglebuttons - Changing state based on state of the others

    Thank you all for your support ...

    StephenR ... I'm thinking that much of your suggestion was the basis of my initial attack which had disastrous consequences. Some weird errors like "Stack overflow" etc which eventually led to a full Excel crash. But yes, this is kinda where i'd like to go with this avoiding the option buttons (which I did get to work!) if possible.

    MickG ... I'm playing with the code you provided. It's providing accurate results, but unsure now how to adapt it further.

    What your code does is simply change the button caption ... if that button was pressed, it displays true, the other display false.

    What I need it to do is depress when true, and then open up a 2nd userform.
    I'm not sure really where to go now ...

  7. #7
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Togglebuttons - Changing state based on state of the others

    I made these changes ....

    Please Login or Register  to view this content.
    Interestingly, when I break the code on the mousedown lines and step through the code, the selected buttons remain depressed. But when I remove the breaks and run the code without interruption or manual stepping, the buttons don't depress.
    ?????? huh ??????

  8. #8
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Togglebuttons - Changing state based on state of the others

    Hopefully its working for you !!!
    Regrds Mick

  9. #9
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    [SOLVED] Re: Togglebuttons - Changing state based on state of the others

    Ahhh! Mick! Nice ... !

    Thank you .... I think you found the winner!

    Thank you everyone for your contributions. You support is really appreciated.

  10. #10
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Togglebuttons - Changing state based on state of the others

    You're welcome

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Networkdays based on state
    By ricky82 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-09-2017, 12:36 AM
  2. Button caption changing depending on macro and current state
    By Darkprophecy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-08-2015, 03:02 AM
  3. [SOLVED] state abbreviations to regular state names
    By ammartino44 in forum Excel General
    Replies: 2
    Last Post: 05-19-2015, 01:39 PM
  4. 50 States, Drop-Down List, select a state then produce the # for that state
    By Sir CHARLES in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-30-2015, 07:46 PM
  5. [SOLVED] Lookup State Name from State Code and and Display in column in COUNTIES worksheet.
    By Jim15 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-11-2014, 02:41 PM
  6. [SOLVED] Changing the state of Labels and textboxes in userforms
    By bfischer414 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-15-2013, 09:53 AM
  7. [SOLVED] Can VB Save hidden/grouped columns state, unhide all, then restore columns to saved state
    By JTwrk in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-27-2012, 02:54 PM

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