Solved

vba to select a combo box entry

Posted on 2011-09-09
4
347 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

863 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

24 Experts available now in Live!

Get 1:1 Help Now