Link to home
Start Free TrialLog in
Avatar of DanSeal100
DanSeal100Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Keeping a list box blank until something is typed into the control the query is based on

Hi,
I have a list box based on a query. I would like the list to appear blank/empty when the form first opens and stay this way until the user types something into one of the controls that the query running the list box is based on.

What is the best way of doing this?
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Something like this:

Private Sub Text1_AfterUpdate()
   Me.YourListBoxName.RowSource = "TheQueryName"
End Sub

Add same code for the other controls the list box is based on.

mx
use the change event of the control...

what is the Rowsource of the Listbox?

private sub textBox_change()
dim str as string, sql
str=str & me.textbox.text

sql="select f1,f2 from tableName where f2 like '" & str & "*'"

me.listbox.rowsource=str

end sub
Avatar of DanSeal100

ASKER

Thanks for your advice, I actually have the control updating the list box on the change event. It re queries the list box to do this.

The only problem is what happens before the user types anything into any of the controls. At the moment before they type anything all the records in the database are shown in the list box and this is a bit confusing to the user. I wondered if there was a way to get the list box to show nothing until the user types something.
remove the row source of the list box from the Property sheet and assign the rowsource in the change event of the textbox

private sub textBox_change()
dim str as string, sql
str=str & me.textbox.text

sql="select f1,f2 from tableName where f2 like '" & str & "*'"

me.listbox.rowsource=str

end sub
ASKER CERTIFIED SOLUTION
Avatar of ldunscombe
ldunscombe
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial