Link to home
Start Free TrialLog in
Avatar of thandel
thandel

asked on

How to display combo box drop down

I have a form that a user enters a zip code and the form can then lookup cities... some cities share the same zip code (technically the same city)  In the past I would look up the zip and if more than 1 using send keys I would display the drop down in the combo box showing just the options for that zip:

Me.cbZip.RowSource = "SELECT tZip.Zip, tZip.City, tZip.State FROM tZip WHERE (((tZip.Zip)=[Forms]!        Me.cbZip.RowSource = "SELECT tZip.Zip, tZip.City, tZip.State FROM tZip WHERE (((tZip.Zip)=[Forms]![FEntry]![cbzip])) ORDER BY tZip.City, tZip.Zip"

SendKeys "{TAB}", True 'move out of combo
SendKeys "+{TAB}", True 'move back into combo
SendKeys "(%{DOWN})", False 'display new findings


However I don't think Send keys is support  any more.... any way to make this work with the same behavior as with the send keys?
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Me.cbZip.DropDown

Open in new window

Correction
Probably you will need
Me.cbZip.SetFocus
Me.cbZip.DropDown

Open in new window

Avatar of thandel
thandel

ASKER

Does not work in the after update, it displays it during the after update but as soon as the sub is done its not displayed.
Maybe you need a requery to refeed the combo after you set the filtered RowSource
Me.cbZip.Requery

Open in new window

Shouldn't a combobox do this all by itself?  What version of Access are you using?
Just to be clear, ....based on John's suggestion, ...your code should look like this:

Me.cbZip.RowSource = "SELECT tZip.Zip, tZip.City, tZip.State FROM tZip WHERE (((tZip.Zip)=[Forms]![FEntry]![cbzip])) ORDER BY tZip.City, tZip.Zip"
Me.cbZip.Requery
Me.cbZip.SetFocus
Me.cbZip.DropDown

Open in new window


...(No sendkeys needed)
Try it like this,....then get back to him
and FYI, sendkeys is still supported.   However SendKeys is always problematic in that the keys are sent to whatever window is currently active.

If your using clicks somewhere else when you issue a sendkeys, they will go to that window, not Access.   Thus the use of sendkeys can be unpredictable.

Avoid sendkeys at all costs.   Should be the very last way you attempt to do something and only if there absolutely is no other way.

Jim.
Avatar of thandel

ASKER

No dice, just doesn't display the found records if I go into the combo then it does.

Been using the same code for 10 years without issue (send keys) now it fails with Win 10.  If you can tell me why it not working then I can correct and reuse send keys for another 10 years  :)

Error with send keys is "permission denied"

If I tab out of the field, then  tab back in and press ALT - DOWN ARROW I get exactly what  I want which is what I was using send keys for.
ASKER CERTIFIED SOLUTION
Avatar of thandel
thandel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm confused, why would you want to reset the rowsource of a combo based on the current selection in that combo.  Normally you would use cascading combos, where you select the zip code from one combo, reset the rowsource property of another combo (cbo_City) and then set the focus to cbo_City and drop it down.