vba to select a combo box entry

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
LVL 5
rberkeConsultantAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Connect With a Mentor Commented:
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
 
mbizupCommented:
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
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
odd ... because it does not work for me ... w/o the change I made.

mx
Capture1.gif
0
 
rberkeConsultantAuthor Commented:
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
All Courses

From novice to tech pro — start learning today.