Solved

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

Posted on 2010-08-23
5
374 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 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now