Combo Box - First Use

D

dave h

Hi,
I have this code:

Dim mySQL As String
Dim myCombo As Control
Set myCombo = Forms("person2").Controls("cboNameSearch")
mySQL = "Select Name, personID FROM person ORDER By Name"
myCombo.RowSource = mySQL

When the form is first brought up, there is no problem if the user clicks on
the dropdown arrow and selects from the list. After that, if a person keys
into the textbox part, the combo box also operates in the normal fashion.

However, when the form is first brought to life and the user starts typing
in the text box part, the combo box does not respond in any way - it just
sits there. For example, if "Ajax" is in the list and the user types some
or all of that word, nothing happens. Hit enter and still nothing happens.
Once the dropdown list part has been exercised at least one time, then
typing in letter "A" immediately shows "Ajax" in the text box.

It seems like I should be doing something to initialize the combo box - any
suggestions?

Thanks, Dave H.
 
D

Douglas J. Steele

Are you sure that the focus is on the combo box when the user starts typing?
What you're describing is not the behaviour I see with combo boxes.
 
D

dave h

Hi Doug,

I've made a little progress by setting focus. Now I get more normal
behavior, but I still have my real problem:

in the Change event for the combo box, I have this code:

If Not IsNull(Forms("person2").Controls("cboNameSearch")) Then
ID = Int(Forms("person2").Controls("cboNameSearch").Column(1))
GetOnePersonData (ID) ' this line uses a sub that populates text
boxes on the form
End If

The IsNull test finds a Null on this first use of the CB as no row seems to
be selected at this point (so does not get any data). However, once the
dropdown arrow has been used one time, then it gets past this test and works
the way I had hoped it would. Strangely, keying into the textbox portion on
these subsequent visits, gets exactly the ID I want. It does not use the ID
from the last visit. So, keying into the text box on these subsequent
visits seems to select a row in the list, whereas the first visit (before
the dropdown is used) does not seem to select a row.

Thanks for your interest and I'll appreciate any more help, Dave H.
 
D

Douglas J. Steele

I'm not sure I understand what you're trying to do. I don't think the Change
event is the appropriate one in this case: use the AfterUpdate event to
ensure that a record has been selected.
 
D

dave h

Thanks Doug, Yes, AfterUpdate (or BeforeUpdate) works much better. I was
trying to respond to each keystoke to show some data, but it is just not
practical - the user will have to tab or CR out of the textbox part of the
CB to see the data - so be it. Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top