Solved

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

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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

771 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

10 Experts available now in Live!

Get 1:1 Help Now