Make button control select from VBA (1 Viewer)

Dave E

Registered User.
Local time
Today, 07:16
Joined
Sep 23, 2019
Messages
104
I have a form with 3 buttons that select 3 views of the data - All data, Archived data and Live data in a subform view. A pop-up form is used for detailed searches but only searches on all of the data. As the existing view on the main form could be any one of the 3 main form button options, I am looking at how to switch the focus and action (as if the button is pressed) to the All Data button before opening the Search form.

I have a notion to set the properties of the button appearance (Pressed Backcolor...etc) and then use the vba routine to ensure that the action of the button is replicated before opening the search form. But could anyone suggest other methods?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:16
Joined
Oct 29, 2018
Messages
21,456
Hi. Not sure I understand what's going on with your form, but maybe just adding a TempVar to identify which button was last selected would help? Or, if you're saying you want to make sure the All button is pressed before calling up the Search form, then maybe just call its Click event.
 

Dave E

Registered User.
Local time
Today, 07:16
Joined
Sep 23, 2019
Messages
104
Thanks for the response. Yes, I want the All Button to be 'pressed' from VBA before the Search Form is opened.
Is it possible to call one OnClick event from another? If so, that would appear to be the cleanest solution.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:16
Joined
Oct 29, 2018
Messages
21,456
Thanks for the response. Yes, I want the All Button to be 'pressed' from VBA before the Search Form is opened.
Is it possible to call one OnClick event from another? If so, that would appear to be the cleanest solution.
Yes, you can usually do something like this.

Call ButtonName_Click
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:16
Joined
May 7, 2009
Messages
19,233
to be able for the Click Event of the button to be called from any
part of your db, make the Sub Public instead of Private:

[Forms]![FormName].ButtonName_Click
 

Dave E

Registered User.
Local time
Today, 07:16
Joined
Sep 23, 2019
Messages
104
Thanks for the responses. I will give it a go. I had a feeling there was going to a more efficient way of doing it.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:16
Joined
Oct 29, 2018
Messages
21,456
Thanks for the responses. I will give it a go. I had a feeling there was going to a more efficient way of doing it.
Good luck and let us know how it goes.
 

Dave E

Registered User.
Local time
Today, 07:16
Joined
Sep 23, 2019
Messages
104
It worked fine. Forms!MainOptions.Command117_Click did the trick after making the Sub Public.

Thanks for the help.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:16
Joined
Feb 19, 2002
Messages
43,224
Rather than using three independent buttons, use a combo box or an option group.
 

Users who are viewing this thread

Top Bottom