Option Group Click Event (1 Viewer)

kirkm

Registered User.
Local time
Tomorrow, 03:41
Joined
Oct 30, 2008
Messages
1,257
There's 14 option buttons on my Form, spread over 5 Option Group controls.
Only one group will be Visible at any one time.
Can a procedure detect which of the 14 has been clicked, or will I need a click event for each button ?
 

isladogs

MVP / VIP
Local time
Today, 14:41
Joined
Jan 14, 2017
Messages
18,186
You state that only one option group will ever be visible,

So I would just have one option group on your form and use select case to determine how many options appear and what captions each should have.
The option group after update event will then work whichever option button is clicked
 

kirkm

Registered User.
Local time
Tomorrow, 03:41
Joined
Oct 30, 2008
Messages
1,257
I would need to build each group as required. so it seemed a good idea to have them all set up in design mode.
But it may work out better as you suggest. I'll try it.
Thanks.
 

isladogs

MVP / VIP
Local time
Today, 14:41
Joined
Jan 14, 2017
Messages
18,186
Its an approach I use regularly & works well. Good luck
 

Micron

AWF VIP
Local time
Today, 10:41
Joined
Oct 20, 2018
Messages
3,476
or will I need a click event for each button ?
Not that you should approach this any differently than what's been suggested, but it brings to mind the situation where the same (or similar) code needs to run for multiple controls. I'd say it's common in these cases to write a public function and then select all necessary controls in design view and put the name of that function as the name of the event to run in whichever event you want to use. In this way, you can assign the same procedure to many controls at once, and only have to write one procedure. If you need specific info (e.g. which control was updated) you can use its name, or tag property value, or any other method that is suitable. Food for thought for the future...
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:41
Joined
Feb 19, 2002
Messages
42,984
or will I need a click event for each button ?
Option groups don't work that way. All of your code will reference the OptionGroup Control rather than individual buttons. The OptionGroup's .value property will contain the value assigned to the button that was clicked.

You could use a combo that is filtered by group so it only shows the items in the group. This method is much more flexible since it doesn't require format changes if you need to add new options. Also, it is more logically correct since it results in only a single value being stored. Your groups seem to be mutually exclusive, that means that there should be a SINGLE group rather than 5. The combo gives you that construct.
 

Users who are viewing this thread

Top Bottom