Option group with alternating toggle buttons (AC2007)

AOB

Registered User.
Local time
Today, 23:45
Joined
Sep 26, 2012
Messages
633
Hi guys,

I have an option group with two toggle buttons. Is it possible to set up the option group such that only one toggle button is visible at any given time (i.e. the unselected option)

So the group has a default value. Clicking the visible button should switch the value, hide the button (option) associated with that value and show the alternate button (option) for the alternate value?

Basically only having one visible button at any given time which toggles between the two values (but I'd like to retain it as an option group, rather than as two independent buttons, as that gives me a handy value from which to determine control sources elsewhere)

I've tried setting the visibility of the buttons from the AfterUpdate event of the option group but it doesn't work.

I know I can do this with independent buttons but was hoping there was a quick(er) and easy way to do it with an option group instead?

Thanks!

AOB
 
Read my signature and try again
 
Apologies spikepl

Here is the code :

Code:
Private Sub fraSummariseBy_AfterUpdate()
 
    With Me
 
        Select Case .fraSummariseBy.Value
 
            Case 1      ' Volumes
 
                .togValues.Visible = True
                .togVolumes.Visible = False
 
            Case 2      ' Values
 
                .togValues.Visible = False
                .togVolumes.Visible = True
 
        End Select
 
    End With
 
End Sub

I have set as initial conditions for the Volumes button (the default option) to be not visible and for the Values button (the alternate option) to be visible. And then the above code should alternate their visibility on each click.

Just tried it again this morning and what's strange is, if I have the two toggle buttons in two different places (i.e. above and below each other), this code actually works. But when I overlay them (so they appear to be one button with just a changing caption), the Volumes button is always visible (it just appears either raised or depressed).

When I click on it, the Values button appears briefly (i.e. only while I hold the mouse button down) and the option switches (when I release the mouse button). So the functionality appears to be working in terms of toggling the option but the visibility aspect does not?

Thanks

AOB
 
Found a workaround but not particularly elegant - I added a separate command button which toggles the value of the option group, then hid the option group. Then I can just change the caption on the single button on each switch.

Code:
Private Sub comVolumesOrValues_Click()
 
    With Me
        Select Case .fraSummariseBy.Value
            Case 1      ' Volumes
                .fraSummariseBy.Value = 2                 ' Switch to Values
                .comVolumesOrValues.Caption = "Volumes"
            Case 2      ' Values
                .fraSummariseBy.Value = 1                 ' Switch to Volumes
                .comVolumesOrValues.Caption = "Values"
        End Select
    End With
 
End Sub

It works but I don't like it as I would rather be changing the value of the option group directly, rather than via another control. And I would have thought this was perfectly possible with a dual-option toggle button setup.

This will work for now but if anyone has any better suggestions I'm all ears...
 

Users who are viewing this thread

Back
Top Bottom