Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vba to select a combo box entry

Posted on 2011-09-09
4
Medium Priority
?
387 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 36514460
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
ID: 36514466
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
ID: 36514482
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
ID: 36515067
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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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