2 txtbox populating 1 listbox

stormin_norm

Registered User.
Local time
Today, 08:00
Joined
Apr 23, 2003
Messages
213
Any best practice on populating a listbox based on which textbox is populated

i.e.
textboxes:
customer name customer id


listbox:
w/ customer id, name, address
Recordsource=qryCustomer

qryCustomer
where customername like txt customer name] & * or customerid=txtcustomerid

When the form first opens, the listbox is autopopulated with ALL records due to the wild card search.
Is the only way to make this work is through code dynamically building the query string for the listbox vs using a query??
 
Broadly speaking, yes on the code, no on dynamically building a string -- unless you like doing that kind of thing. You can, optionally, create and save queries and then simply change the rowsource property of your listbox as needed.

Code:
If me.txtBoxName1 = "Howdy Dowdy" Then
	Me.lstBoxWhatEver.RowSource = "QryHowdy"
Else
	Me.lstBoxWhatEver.RowSource = "QryCus"
End if

You can also, if you like, leave the listbox rowsource empty and only change the rowsource property when something is entered into your textbox (look up the Change Event in Help or search here) -- this will stop the listbox from pulling records when the form initially loads.

Practice with it a bit and it'll come together...

Regards,
Tim
 
Thanks.
Good solution with minimal coding. This works perfect.

-Stormin'
 

Users who are viewing this thread

Back
Top Bottom