I'd use a combobox that the user can type into rather than a
seperate textbox. Then make sure the query that fills the
combobox is sorted.
When the user types in the first few letters of a company name
the combo box can automatically advance to the company
name and if needed other fields on the form can be updated.
For an HTML/javascript that's works in the same manner:
http://www.microcosmotalk.com/tech/scripts/
If you click on the Country Listbox there and type the first few
letters of a country there, you'll see how the form updates the
rest of the information in the other listboxes and appropriate
textfields. While that page is NOT Access or Visual Basic for
Applications coding, it is Javascript and you can make the
combo boxes in Access perform in the same manner.
Hope that helps.
--
Jim Carlock
http://www.microcosmotalk.com/
Post replies to the newsgroup.
Jen said:
Hi Dirk,
I wanted to do a string search for a list box data,
because a list box has more than 5 thousand records(such
as company names), and a list box doesn't have the
feature of search record, if I just scroll down the list
box to find a record that I wanted, it will be a
nightmare. So I was thinking if I can type a string in a
text box which can match the string in the list box, that
will solve my problem.
Can you give me any suggestions or examples? Thank you
very much for any help.
I can think of several ways to go about this. The most elegant, to my
mind, though it's not exactly what you asked for, is to use the text box
as a criterion for the list box's RowSource query, requerying the list
box after an entry is made in the text box so that the list box shows
only those entries that match the string you entered in the text box.
There's even a way to work it so that the list box is requeried with
each keystroke, quickly narrowing down the list of entries to a short
list containing the one you want.
Another approach is to use a subform instead of a list box. Then you
can use the text box's AfterUpdate event to set the focus to the the
desired field on the subform, and then execute the DoCmd.FindRecord
method to find the record that matches the text box. Or you can use DAO
code to search the subform's recordset for the matching record.
Yet another approach would be to stick with a list box, and loop through
the list box's ItemData collection looking for a row whose ItemData
matches the text box.