Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Jun 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Please Help Stop Toggle Button Looping (Word 2000)

    I have created a VBA userform in WORD 2000 which has 20 toggle buttons. When each button is pressed a different form appears beside the toggle buttons. I am trying to find a way to make the value of the other buttons false when a new button is pressed - so that only one button is highlighted/depressed at any given time. I have tried creating a sub with all toggle button values set to false then calling the sub when each button is pressed. This works fine for button 1 but when button 2 is pressed I can see in the step through that when the code for button 2 is finished the next step goes to button 1. When button 3 is pressed the program steps through button 3, then button 1, then button 2. It is like it reaches the sub with the default settings and for each button with a set value it goes to the click action. I have tried setting the defaults in each button but it stills seems to step into the click action of the next button. I don't know why it steps into the click action of the next button in the list of default false settings. Everything works perfectly if the button values remain as true even when you click on another button, however this will not give users a true indication of which form they currently have active.
    Please can someone advise of the best way to make the current toggle button true and all the others false without getting into this loop. What I would like is for only the current toggle button to appear depressed. Any ideas or suggestions would be appreciated.
    Thanks
    Suzie <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Please Help Stop Toggle Button Looping (Word 2000)

    Use Option Buttons (radio buttons) instead of toggle buttons. Only one option button in a group can be "On" at a time, so you won't have to write code to do turn them off yourself.

  3. #3
    New Lounger
    Join Date
    Jun 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Please Help Stop Toggle Button Looping (Word 2000)

    Thanks Hans. We considered the radio button option, however we have a number of aged (60+) users who would find it difficult to see or click on radio buttons. Any other suggestions would be appreciated.
    Cheers
    Suzie <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Please Help Stop Toggle Button Looping (Word 2000)

    Clicking the caption of a radio button has the same effect as clicking the radio button itself. If you make the font of the caption large and bold, it should be just as easy to read and click as a toggle button.

    The reason I'm harping on this is that if you run code from the OnClick event of one toggle button to change the value of other toggle buttons, this will trigger the OnClick event for all those other toggle buttons. You can probably get around this using a module-level variable (haven't worked it out, though), but why do all that work if it can be done for you automatically?

  5. #5
    New Lounger
    Join Date
    Jun 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Please Help Stop Toggle Button Looping (Word 2000)

    Thanks Hans. I will keep this in mind and keep looking for other solutions - the form looks pretty ugly with 20 radio buttons and our users don't really want them. You have given me food for thought with the variable. Thanks again.
    Cheers
    Suzie <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Please Help Stop Toggle Button Looping (Word 2000)

    Second idea! A control I seldom use, the TabStrip, can be arranged as a vertical stack of "buttons" which automatically permit one and only one to be depressed at a time. I'm attaching a picture of the run-time view of this kind of tabstrip, along with a design-time view of how you change the labels.

    This might work as well for your application, but I suspect that more code changes would be required. Note: To add tabs, right-click an existing tab to get a very short shortcut menu and choose New Page. The Rename dialog also is called up from this menu.

  7. #7
    New Lounger
    Join Date
    Jun 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Please Help Stop Toggle Button Looping (Word 2000)

    Thanks. The Tabs are great. They appear to have solved our problem.
    New problem - if you can assist - I now need to save the userform with a changed set of default textbox values to the new Word document so that the original defaults in the template don't change but the document retains the values in the userform when it is next opened. I would appreciate any assistance you can give.
    Cheers
    Suzie <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  8. #8
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Please Help Stop Toggle Button Looping (Word 2000)

    The usual approach for a problem like this is to store the information in Document variables and to populate the userform in the FormActivate event.

    Have a look at ActiveDocument.Variables.Add and similar methods in the helpfile.

    If you need a more detailed example then ask again.

    StuartR

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Please Help Stop Toggle Button Looping (Word 2000)

    <P ID="edit" class=small>(Edited by jscher2000 on 19-Mar-03 17:26. Had second thoughts...)</P>How about something like this?

    <pre>Private Sub ToggleButton1_Click()
    Call ToggleMyToggleButtons
    ' The rest of your code
    End Sub

    Private Sub ToggleButton2_Click()
    Call ToggleMyToggleButtons
    ' The rest of your code
    End Sub

    ' Etc.

    Sub ToggleMyToggleButtons()
    Dim ctrl As Control
    For Each ctrl In Me.Controls 'Check every control on the UserForm
    If TypeName(ctrl) = "ToggleButton" Then
    If Not Me.ActiveControl.Name = ctrl.Name Then
    ' This ToggleButton is not the one the user clicked, turn it off
    ctrl.Value = False
    End If
    End If
    Next ctrl
    End Sub</pre>

    I've only done limited testing, and I've never used ToggleButton controls before, but it seems to work and to require minimal changes to your code.

    Afterthought:

    The following would seem to be more efficient, but I'll admit I haven't tested it:
    <pre>Sub ToggleMyToggleButtons()
    Dim ctrl As Control
    For Each ctrl In Me.Controls 'Check every control on the UserForm
    If TypeName(ctrl) = "ToggleButton" Then
    ' If this ToggleButton has been turned on, check whether it should be turned off
    If ctrl.Value = True Then
    If Not Me.ActiveControl.Name = ctrl.Name Then
    ' This ToggleButton is not the one the user clicked, turn it off
    ctrl.Value = False
    Exit For
    End If
    End If
    End If
    Next ctrl
    End Sub</pre>

    The idea here is to reduce the number of times you interrogate the Me.ActiveControl.Name property to one or two times, not once for each control. The Exit For statement takes advantage of the fact that only one button should be True, and once you've turned off the one that shouldn't be True, you're done.

Posting Permissions

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