Selecting value on Listbox

G

Guest

Hi, can anyone help a recent Access user

I have a text box (txtText) above a list box (txtList) on a form
(frmGetSubDivInfo).
The plan is for the user to enter some text into the text box and when enter
is hit
some code runs (AfterUpdate property).

The code finds the closest match in the underlying table bound to txtList
(tblSubDivIndex). I then want txtList to goto the record found in
tblSubDivIndex
and highlight it on the form. There are several hundred records in
tlbSubDivIndex
so all the records can not be viewed at the same time.

The code snippet I am attempt to use gives me a strange error, the code is
below:

'match found so update list box
Debug.Print "B7- match found for "; intKeyNum; " ,update txtList"
[Forms]![frmGetSubDivInfo]![txtList].Value = _
DLookup("[SubDivLabel]", "tblSubDivisionIndex", _
"[KeyID] = intKeyNum")

This code worked randomly, now it doesn't at all.
No row highlights and I get a strange error. The error I get is:

"You cancelled the previous operation"

If I change the code to :

'match found so update list box
Debug.Print "B7- match found for "; intKeyNum; " ,update txtList"
[Forms]![frmGetSubDivInfo]![txtList].Value = _
DLookup("[SubDivLabel]", "tblSubDivisionIndex", _
"[KeyID] =" & trim(str(intKeyNum)) )

The error goes away but still no highlighted row. What am I missing?
Any help is greatly appreciated.
 
J

Jeff Boyce

The combination of a search textbox and a results listbox sounds very much
like ... what a combo box does! Have you looked at that as an option?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
G

Guest

Hi Jeff,

I thought about a combo box but I didn't think it would be a
good solution for due to all the scrolling up and down to find
the desired selection.

But maybe I missed something. What did you have in mind?
 
J

Jeff Boyce

You don't have to scroll around. You can set the property on the combo box
to auto-complete when you start typing.

If your combo box had a list of States in the US, and you typed an "A", the
combo box would drop down and jump to (lessee if I can remember) "Alabama".
If you then typed an "r", the combo box would jump to the first State that
starts with "Ar" (?Arizona). If you then typed a "k", the combo box would
jump to "Arkansas" (if I'm recalling state names correctly).

Just start typing and the combo box finds the first item that starts with
those characters.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 

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