Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-08-23
5
Medium Priority
?
424 Views
Last Modified: 2012-05-10
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?
0
Comment
Question by:DanSeal100
5 Comments
 
LVL 75
ID: 33503981
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
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 33504017
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
0
 

Author Comment

by:DanSeal100
ID: 33504948
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.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 33505413
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
0
 
LVL 14

Accepted Solution

by:
ldunscombe earned 2000 total points
ID: 33507219
Another method that may suit your needs is to simply hide the list box altogether and simply make it  visible on the change event of your controls.
me.ListBox.visible = true
You could also hide it again while moving from record to record with your forms OnCurrent event
me.ListBox.visible = false
Leigh
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question