Solved

vba to select a combo box entry

Posted on 2011-09-09
4
335 Views
Last Modified: 2012-08-14
I have a combo box which shows a state, city and zip code.  The user types a state name then selects the correct zipcode record.

I also have a text box in which the user can key a zip code.  Txtbox_exit uses the zipcode to force the combo box to show that state.

The attached mdb file shows my problem.  When txtbox_exit is done, the wrong record is highlighted.  

What am I doing wrong.  (Please don't suggest radically different approaches, I want to keep the general structure as is.)

show-problem.png
db10.mdb
0
Comment
Question by:rberke
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
Comment Utility
Seems all you need is this:

Private Sub txt2PickZip_Exit(Cancel As Integer)

Me.cboSortByZip = Me.txt2PickZip
Me.cboSortByZip.SetFocus
Me.cboSortByZip.Dropdown

End Sub

mx
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
Strange -

It is working perfectly for me.

I can type in 22222, then tab out of the textbox, or click somewhere else, and the second row of the combo is correctly highlighted.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
odd ... because it does not work for me ... w/o the change I made.

mx
Capture1.gif
0
 
LVL 5

Author Closing Comment

by:rberke
Comment Utility
Thanks, that is much simpler.  

mbizup:  You are correct, sometimes my code seemed to work.  Other times it did not.  I have no idea why.

but Mx code seems perfect.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now