Function for auto dropdown for all combobox (1 Viewer)

calvinle

Registered User.
Local time
Today, 06:37
Joined
Sep 26, 2014
Messages
332
Hi,

In a form, I have more than 20 combobox, and I would like to create a function so I on GotFocus, it will automatically dropdown that combobox.

Any idea how can I make it work instead of adding a code individually to each combobox?

Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:37
Joined
Oct 29, 2018
Messages
21,358
Hi. You might be able to create a Class Module to automatically assign that behavior to all comboboxes on a form.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 08:37
Joined
Feb 28, 2001
Messages
27,001
Look at this article:

https://docs.microsoft.com/en-us/office/vba/api/access.combobox.dropdown

In essence, use the .DropDown method of the combo box object, which you certainly could trigger on the GotFocus event. Not quite the same as what you requested, but it would be a one-line edit for each dropdown.

To make it totally automatic, you need to play with creating your own variant control class (i.e. some object-oriented programming.)

EDIT: theDBguy beat me to the OOP part.
 

nhorton79

Registered User.
Local time
Tomorrow, 02:37
Joined
Aug 17, 2015
Messages
147
You could do this on each Gotfocus event

Code:
Me.comboboxname.Dropdown




Sent from my iPhone using Tapatalk
 

calvinle

Registered User.
Local time
Today, 06:37
Joined
Sep 26, 2014
Messages
332
You could do this on each Gotfocus event

Code:
Me.comboboxname.Dropdown




Sent from my iPhone using Tapatalk

Yes I know but doing this I need to add the code to each individual combobox one at a time.

Thanks
 

calvinle

Registered User.
Local time
Today, 06:37
Joined
Sep 26, 2014
Messages
332
Look at this article:

https://docs.microsoft.com/en-us/office/vba/api/access.combobox.dropdown

In essence, use the .DropDown method of the combo box object, which you certainly could trigger on the GotFocus event. Not quite the same as what you requested, but it would be a one-line edit for each dropdown.

To make it totally automatic, you need to play with creating your own variant control class (i.e. some object-oriented programming.)

EDIT: theDBguy beat me to the OOP part.

Thanks. I figure it out.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:37
Joined
Oct 29, 2018
Messages
21,358
Thanks. I figure it out.

Hi. Does that mean you have figured it out, or does it mean you are going to figure it out? If you have figured it out, you might consider sharing your solution with others. Just a thought...
 

calvinle

Registered User.
Local time
Today, 06:37
Joined
Sep 26, 2014
Messages
332
Hi. Does that mean you have figured it out, or does it mean you are going to figure it out? If you have figured it out, you might consider sharing your solution with others. Just a thought...

Sure.

Basically, I created a Public Function, then I wud call that in the combobox GotFocus fire event.

Code:
Public Function ShowDropDown() As String
 Screen.ActiveControl.DropDown
End Function

I just select all the combobox, and in GotFocus, I call the function: =ShowDropDown()

Once the field has a focus, it will show the drop down.

Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:37
Joined
Oct 29, 2018
Messages
21,358
Sure.

Basically, I created a Public Function, then I wud call that in the combobox GotFocus fire event.

Code:
Public Function ShowDropDown() As String
 Screen.ActiveControl.DropDown
End Function

I just select all the combobox, and in GotFocus, I call the function: =ShowDropDown()

Once the field has a focus, it will show the drop down.

Thanks
Hi. Good job! Thanks for sharing. Good luck with your project.
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:37
Joined
Sep 21, 2011
Messages
14,052
How is that any different from calling the dropdown method directly from the gotfocus event?

I can understand it if there was a lot more going on in the function, but just as it is, I cannot see any benefit.?:confused:

Sure.

Basically, I created a Public Function, then I wud call that in the combobox GotFocus fire event.

Code:
Public Function ShowDropDown() As String
 Screen.ActiveControl.DropDown
End Function

I just select all the combobox, and in GotFocus, I call the function: =ShowDropDown()

Once the field has a focus, it will show the drop down.

Thanks
 

missinglinq

AWF VIP
Local time
Today, 09:37
Joined
Jun 20, 2003
Messages
6,423
Because in Design View he can select all 20 Comboboxes at once...go to the OnGotFocus Property...and enter =ShowDropDown() once...as opposed to having to create 20 events, one at a time...explicitly, naming each Combobox, i.e. Me.Combo1.Dropdown, Me.Combo2.Dropdown, Me.Combo3.Dropdown etc.

Linq ;0)>
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:37
Joined
Sep 21, 2011
Messages
14,052
Ah, OK, I *thought* that multi selection trick could still be done to enter the same code in multiple controls, not just with a function. :eek:

Because in Design View he can select all 20 Comboboxes at once...go to the OnGotFocus Property...and enter =ShowDropDown() once...as opposed to having to create 20 events, one at a time...explicitly, naming each Combobox, i.e. Me.Combo1.Dropdown, Me.Combo2.Dropdown, Me.Combo3.Dropdown etc.

Linq ;0)>
 

Users who are viewing this thread

Top Bottom