Selecting a Combobox Item From VBA

G

geoaerocfi

I'm trying to change a combobox's current selection by writing the item I
want in the text-box, using either just the name of the combobox (Me!cbox),
or the Value-version: (Me!cbox.Value).

Either way the textbox changes, just like I want, and the new item (not new
to the listbox, just the listbox item I wanted) shows up in the textbox. But
nothing else happens. The combobox doesn't know that the 'user' (VBA) has
entered the data, and tried to change the selection.

The closest I've come is to add .SetFocus and .Dropdown, after the
text-copy. Then the listbox drops down, and if the user hits Enter, the item
is indeed selected. OK, but not elegant.
 
A

Allen Browne

Just assign the value to the combo, e.g.:
Me.cbox = 999

Note that if the bound column is not the display column, you must assign the
hidden value (not the text that you actually see.) Therefore you may need to
use a DLookup() to get the correct value to assign.
 
J

John Spencer

If you mean you want one of the combobox actions to execute after you
have used VBA to change the combobox value, then you are correct that
nothing happens.

You have to use your code to force the action to occur, by calling the
routine. If your calling VBA routine is not in the form's code then the
form routine you want to execute will have to be changed from a Private
routine to a Public routine.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top