Order of Events in an Option Group (1 Viewer)

JMongi

Active member
Local time
Today, 04:53
Joined
Jan 6, 2021
Messages
802
So, here's an interesting one. What is the order of exectution of OnClick events when a toggle button in an option group is selected?

Per MS, the Option Group frame OnClick event fires in the order of BeforeUpdate/AfterUpdate/OnClick.

But, the info on the OnClick event for an individual toggle button does not specify its order of firing relative to the frame control. Does anyone know or have a reference for option groups?
 

cheekybuddha

AWF VIP
Local time
Today, 09:53
Joined
Jul 21, 2014
Messages
2,280
Normally with an option group you are only interested in the option group Change event, or maybe its AfterUpdate, so I don't know what order the events occur in relation to the actual radio button/chackbox/ toggle button being clicked.

However, it's easy enough to test. Just place code in each event that you are interested in like:
Code:
Private Sub fraYourFrame_Change()
  Debug.Print "fraYourFrame_Change"
End Sub

Private Sub fraYourFrame_AfterUpdate()
  Debug.Print "fraYourFrame_AfterUpdate"
End Sub

Private Sub option1_click()
  Debug.Print "option1_click"
End Sub

Private Sub option1_MouseUp()
  Debug.Print "option1_MouseUp"
End Sub

' ... etc

Then click your radio button or toggle button and paste back here the output from the Immediate Window (Ctrl+G)
 

moke123

AWF VIP
Local time
Today, 04:53
Joined
Jan 11, 2013
Messages
3,920
The toggles in an option group have no before/after onclick events. Those events occur in the frame. Can't say that I've ever used any other event with an option group other than afterupdate. I do use the value of the frame in other code whether clicked on or not by setting a default value for the group.
 

JMongi

Active member
Local time
Today, 04:53
Joined
Jan 6, 2021
Messages
802
@moke123 - I'm not sure what you are referring to. Both the frame and the toggle have click events. I can select them in the VBA editor and its referenced in the MS help file.

I'm probably trying to do this a complicated way, but my question is also intresting (curiosity and all that).

I want to change the bevel property of the toggle button on click. That's easy enough. But, the bevel property might have been set by a previous click. So, I need to set all the other toggle button bevels to their standard state.
 

cheekybuddha

AWF VIP
Local time
Today, 09:53
Joined
Jul 21, 2014
Messages
2,280
Hmmm....

Just make the changes in the frame change or afterupdate events
 

JMongi

Active member
Local time
Today, 04:53
Joined
Jan 6, 2021
Messages
802
@moke123 - My apologies. I did not read clearly enough. You are correct.

Also, whoever wrote the MS help file....sheesh. You don't copy and paste the same thing with a little blurb at the top that says "by the way, doesn't actually apply to what you think it does...." You put a blurb that says "Does not apply" and then a link to the actual object and method that applies.
 

JMongi

Active member
Local time
Today, 04:53
Joined
Jan 6, 2021
Messages
802
For posterity,

I put a debug.print in the toggle button "BeforeUpdate, AfterUpdate, Click" events
I put a debug.print in the opton group (frame) "BeforeUpdate, AfterUpdate, Click" events

When clicking on a button on a form only the option group events fire (as @moke12 correctly stated).
BeforeUpdate
AfterUpdate
Click
 

JMongi

Active member
Local time
Today, 04:53
Joined
Jan 6, 2021
Messages
802
Hmmm....

Just make the changes in the frame change or afterupdate events
I was trying not to hard code each individual button status into the update event. but, that might be the most expedient way.
 

cheekybuddha

AWF VIP
Local time
Today, 09:53
Joined
Jul 21, 2014
Messages
2,280
I was trying not to hard code each individual button status into the update event. but, that might be the most expedient way.
You'll probably don't have to.

Post the code you are using.

I'm on my phone at the moment, but will try and post a generic solution when I get back to a computer
 
Last edited:

moke123

AWF VIP
Local time
Today, 04:53
Joined
Jan 11, 2013
Messages
3,920
tog.PNG


In the afterupdate of the frame

Code:
    Me.Toggle3.Bevel = 0
    Me.Toggle4.Bevel = 0

    Select Case Me.Frame0

        Case 1
            Me.Toggle3.Bevel = 1

        Case 2
            Me.Toggle4.Bevel = 1
    End Select
 
Last edited:

cheekybuddha

AWF VIP
Local time
Today, 09:53
Joined
Jul 21, 2014
Messages
2,280
Code:
Private Sub Frame0_AfterUpdate()

  Dim vValue As Variant, ctl As Control

  With Me.Frame0
    vValue = .Value
    For Each ctl In .Controls
      If ctl.ControlType = acToggleButton Then
        ctl.Bevel = -(ctl.OptionValue = vValue)
      End If
    Next
  End With

End Sub
(NB aircode!)
 
Last edited:

JMongi

Active member
Local time
Today, 04:53
Joined
Jan 6, 2021
Messages
802
@moke123 - My code works a lot like yours.
@cheekybuddha - I'm going to have to unpack your code a little more. I think I understand teh concept...
 

cheekybuddha

AWF VIP
Local time
Today, 09:53
Joined
Jul 21, 2014
Messages
2,280
@cheekybuddha - I'm going to have to unpack your code a little more. I think I understand teh concept...
As I mentioned, it is untested!

But the premise is that an option frame has its own .Controls collection that contains all its radio buttons/checkboxes/toggle buttons.

Loop through each comparing their .OptionValue to the frame's .Value - if they match, set .Bevel = 1, otherwise set .bevel = 0

(If you want to use different .Bevel values, then you can use an IIf() statement)

(I have never come across .Bevel of a toggle button since I only have Access 2007!)
 

JMongi

Active member
Local time
Today, 04:53
Joined
Jan 6, 2021
Messages
802
It's one of those unexposed properties that you can set via vba.
Where is the comparison being made in your code?
I see placing the frame value in the variant variable. I see cycling through the controls in the frame.
I see you checking for control type.
I don't fully understand ctl.Bevel = -(ctl.OptionValue = vValue)
 

cheekybuddha

AWF VIP
Local time
Today, 09:53
Joined
Jul 21, 2014
Messages
2,280
ctl.Bevel = -(ctl.OptionValue = vValue)
Break it down:

ctl.OptionValue = vValue evaluates to either True or False (-1 or 0)

Multiply by -1: evaluates to either 1 or 0

Set the .Bevel of the toggle button to the result (1 for Circle, 0 for None)
 

cheekybuddha

AWF VIP
Local time
Today, 09:53
Joined
Jul 21, 2014
Messages
2,280
I used 1 and 0 in my example. I think that's where David got those numbers.
Spot on!

I had looked up that reference to find out what the numbers meant!

If you wanted to use other values, as I mentioned, you can use an IIf() statement:
Code:
Public Const BevelEffectNone = 0
Public Const BevelEffectCircle = 1
Public Const BevelEffectRelaxedInset = 2
Public Const BevelEffectCross = 3
Public Const BevelEffectCoolSlant = 4
Public Const BevelEffectAngle = 5
Public Const BevelEffectSoftRound = 6
Public Const BevelEffectConvex = 7
Public Const BevelEffectSlope = 8
Public Const BevelEffectDivot = 9
Public Const BevelEffectRiblet = 10
Public Const BevelEffectHardEdge = 11
Public Const BevelEffectArtDeco = 12

' ...
      If ctl.ControlType = acToggleButton Then
        ctl.Bevel = IIf(ctl.OptionValue = vValue, BevelEffectArtDeco, BevelEffectNone)
      End If
' ...
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 04:53
Joined
Feb 19, 2002
Messages
43,275
I still don't understand what you are trying to do but I added some log events to a test form and this is what I see.
The form opens with focus in the TypeDesc at the bottom. Clickinto the first option runs the listed events. Start from the bottom up. The gotFocus event of the first option fires, then the enter for the control, followed by the beforeupdte, afterupdate, and click.

The second picture shows what happens when I click on the second option. Pick up from 6-10
xxOptionGroupEvent.JPG

xxOptionGroupEvent2.JPG
 

Users who are viewing this thread

Top Bottom