Solved

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

Posted on 2010-08-23
5
414 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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