Textbox bound to listbox

DrMaestro

Registered User.
Local time
Today, 02:40
Joined
Feb 3, 2007
Messages
21
Hi,

I have a listbox which displays the results of a query activated by a button click. I also have a textbox. I want the textbox to display the number of records found (like "X records exist." where X is the number of records). I set the textbox's control source to the ListCount value of the listbox. The problem is, when I start the database the textbox shows "1 records exist" even if didn't start the search (by clicking the search button). After entering the required search parameter and clicking the search button the correct number of records found is displayed. How can I stop the textbox displaying 1 record at the beginning when the listbox is empty?

Thank you very much
 
From VBA help on ListCount:
If you set the ColumnHeads property to Yes, the row of column headings is included in the number of rows returned by the ListCount property. For combo boxes and list boxes based on a table or query, adding column headings adds an additional row.
 
Hi RuralGuy,

Thanks for your answer. The columnheads property is already set to No. There probably is another solution. (When the listbox is empty, I can click on the first row and it is selected. So, the listbox has a selectable empty line, which is counted as a record. I tried to set the default value of the listbox to Null but that doesn't change anything. Also, after searching the database, the number of records found is right. (It is not +1))
Thanks again.
 
A new record always exists, even if it's empty (NULL or otherwise). To get the proper list count, use .ListCount-1 as your formula.

If you don't want users to click on an empty listbox, set the Locked property to "Yes" to prevent any selection until the listbox is in use (at which point you have to unlock it).
 
Hi,

I tried listcount -1 in my formula. When you start the database the textbox states correctly that there are no records. But when you search and find records the number given is 1 less than the actual number. I think I have found a workaround and wanted to share it with you (well it is no rocket science but may help newbies like me). Instead of linking the control source of the textbox to the listcount of the listbox, I added the line of code (without -1) to the OnClick property of the search button. By doing this, I avoided the first "1 record found" phenomenon due to the empty record of the listbox.

Thanks for everyone helping..
 

Users who are viewing this thread

Back
Top Bottom