Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search a listbox

Status
Not open for further replies.

WMitchellCPQ

Programmer
Sep 28, 2001
54
0
0
US
I have a list box which is quite large .. say 16000 records
I need to figure out a good way of searching it..
I had a while loop to search the whole list but that is now taking too much time. I ran into this API method:

Code:
lngindex = SendMessageString(List1.hwnd, LB_FINDSTRINGEXACT, -1, strFind)    
		' Note that we can look for a partial match with LB_FINDSTRING
		' (as long as it begins the string)

but i cant seem to get it to work
It may be as I refering to my forms oddly .. Im using this sort of approach:

Form_frm_PO_MaintainOrders.lstOutstandingOrders.Selected(k) = True

Can someone help to to search my listbox in a better way or tell me how to use the above method ? I seem to be running into problems with . hwnd bit

Cheers
W
 
Hmmmm

You may want to consider a work-around. This is something I have seen that was effective for your situation.

For this situation, you want to search phone numbers.

You have an unbound text box, called qryPhoneNo. It used an OnKey event procedure...
- tested for 3 or more characters typed in the text box
- if less than 3 charcters, do nothing
- if 3 characters or typed, then a SQL statement is built...
SELECT PhoneNo, AreaCode from Contact Where PhoneNo Like
"Me.qryPhoneNo*"

The SQL statement would then be used as the RecordSource for a small subform that acts like a listbox. The selected record in the subform can then be used as the RecordSource for the main form.

The advantage of this approach is that reduce the number of records retrieved since no activity occurs until 3 characters are typed.

There are variations to this approach.

Richard
 
I agree with willir,
but, would like to add, that maybe append the SQL, to the RowSource of the ListBox?

Secondly, your control referencing, I believe is incorrect..

This...
Form_frm_PO_MaintainOrders.lstOutstandingOrders.Selected(k) = True

Should be either...

Forms!Form_frm_PO_MaintainOrders.lstOutstandingOrders.Selected(k) = True

or, if called from form class module...
Me.lstOutstandingOrders.Selected(k) = True

Just for the record, you could also try

Me.lstOutstandingOrders.Value = Me.txtSearch

Otherwise, using the Selected property, you need to know the index value (out of 16000 records, how would anyone know that?). With the value property, you can type a data value, (based on the bound column, which may need to be adjusted).

Good luck!



 
You are on a tear dboulos - this and other posts.

WMitchellCPQ

You may have already done this, but please be aware of the settings for Access...

From the database window, select "Tools" -> "Options" -> "General" tab, and note the value for the field...
"Don't display lists where more than this number of records read:"

Richard
 
Sorry willir, you may have a point!
 
No problem dboulos - you definitely add value to this and the other posts - late night huh?
 
...Late night indeed. Possibly a bit, too late...

I appreciate the understanding, willir!
Thank-you for the compliment, the feeling is mutual!

I'll be looking forward to reading other threads, that invariably, you'll be involved in!








 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top