List Box ListCount property seems to be incorrect...

B

Bob Howard

Using A2K, I have a ListBox with a query behind it to obtain the data to
reveal. In the application, I occasionally need to requery this ListBox
since my program can be adding, deleting and/or changing the data that might
be showing in the ListBox. I also have the need (within the VBA behind the
form) to test (immediately after the requery) whether the ListBox is empty,
and I do this by comparing its ListCount property to zero.

When the ListBox contains data, the ListCount property correctly contains
the actual number of rows of data.

When the ListBox contains no data, the ListCount property always contains
the number 1 (a positive 1).

The ListBox's ColumnHeads property is set to "No."

[p.s. --- when I test this with ColumnHeads=Yes, an empty ListBox **still**
has a ListCount of 1, but a ListBox with data has a ListCount equal to the
number of data rows plus 1 (for the header)]

Why isn't the ListCount property for an empty ListBox zero (ColumnHeads=No)?

Bob (@Martureo_Org)
 
A

Allen Browne

Bob, I am unable to reproduce this in Access 2000 or 2003, using either a
standard or multi-select list box.

What I did was to create a simple unbound form, with a list box that has the
Category table as RowSource.

In the Immediate widow (Ctrl+G) I get the correct count from:
? Forms!frmListBox.MyListbox.ListCount

Still in the Immediate window, I change the RowSource so no records match:
Forms!frmListBox.MyListbox.RowSource =
"SELECT * FROM Category WHERE (False);"

Then asking for the ListCount returns zero.
 
B

Bob Howard

Allen; Thanks --- I'll give this another try tomorrow. I temporarily
replaced the ListCount with a Dcount function to count the number of records
in the RowSource and this is giving me the correct answer (at a greater
cost --- overhead). Bob.

Allen Browne said:
Bob, I am unable to reproduce this in Access 2000 or 2003, using either a
standard or multi-select list box.

What I did was to create a simple unbound form, with a list box that has the
Category table as RowSource.

In the Immediate widow (Ctrl+G) I get the correct count from:
? Forms!frmListBox.MyListbox.ListCount

Still in the Immediate window, I change the RowSource so no records match:
Forms!frmListBox.MyListbox.RowSource =
"SELECT * FROM Category WHERE (False);"

Then asking for the ListCount returns zero.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Bob Howard said:
Using A2K, I have a ListBox with a query behind it to obtain the data to
reveal. In the application, I occasionally need to requery this ListBox
since my program can be adding, deleting and/or changing the data that
might
be showing in the ListBox. I also have the need (within the VBA behind
the
form) to test (immediately after the requery) whether the ListBox is
empty,
and I do this by comparing its ListCount property to zero.

When the ListBox contains data, the ListCount property correctly contains
the actual number of rows of data.

When the ListBox contains no data, the ListCount property always contains
the number 1 (a positive 1).

The ListBox's ColumnHeads property is set to "No."

[p.s. --- when I test this with ColumnHeads=Yes, an empty ListBox
**still**
has a ListCount of 1, but a ListBox with data has a ListCount equal to the
number of data rows plus 1 (for the header)]

Why isn't the ListCount property for an empty ListBox zero
(ColumnHeads=No)?

Bob (@Martureo_Org)
 
B

Bob Howard

Allen;

I testet this again and it's still failing (the Dcount returns the correct
value, however).

In checking further, I found the following:
http://www.experts-exchange.com/Databases/MS_Access/Q_21408560.html

So this is not a new issue!

I'll go thru their recommendations and report back later today.

Thanks again!

Bob (@Martureo_Org)

Allen Browne said:
Bob, I am unable to reproduce this in Access 2000 or 2003, using either a
standard or multi-select list box.

What I did was to create a simple unbound form, with a list box that has the
Category table as RowSource.

In the Immediate widow (Ctrl+G) I get the correct count from:
? Forms!frmListBox.MyListbox.ListCount

Still in the Immediate window, I change the RowSource so no records match:
Forms!frmListBox.MyListbox.RowSource =
"SELECT * FROM Category WHERE (False);"

Then asking for the ListCount returns zero.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Bob Howard said:
Using A2K, I have a ListBox with a query behind it to obtain the data to
reveal. In the application, I occasionally need to requery this ListBox
since my program can be adding, deleting and/or changing the data that
might
be showing in the ListBox. I also have the need (within the VBA behind
the
form) to test (immediately after the requery) whether the ListBox is
empty,
and I do this by comparing its ListCount property to zero.

When the ListBox contains data, the ListCount property correctly contains
the actual number of rows of data.

When the ListBox contains no data, the ListCount property always contains
the number 1 (a positive 1).

The ListBox's ColumnHeads property is set to "No."

[p.s. --- when I test this with ColumnHeads=Yes, an empty ListBox
**still**
has a ListCount of 1, but a ListBox with data has a ListCount equal to the
number of data rows plus 1 (for the header)]

Why isn't the ListCount property for an empty ListBox zero
(ColumnHeads=No)?

Bob (@Martureo_Org)
 
B

Bob Howard

I didn't subscribe, and I just scrolled down to the "solution." There were
several attempts at a "solution" but none of them worked for me. On that
forum, the thread was eventually closed by the amdinistrator due to no
activity after a certain point. Nothing definitive was ever established,
although it's the identical problem I'm having.

By the way, I have ZERO background in SQL, so the RowSource query is a
"regular" Access query.

Per one of that thread's suggestions, I made the query read-only by
specifying that the columns be "Groupped" (taking away the extra null record
used for additions) but that didn't help. I also tried setting the
RowSourceType to "" and then back to "Table/Query" and that also didn't
help. Nothing seems to help.

Bob.
 
A

Allen Browne

Okay, the poster said:
Initially the database had a access backend
My code used to reset rowsource i.e.
lstbox.RowSource = ""
the rowsource type is "Table/Query"
the listcount is zero,
but when moving to mysql backend, the listcount became 1.

Are you working with an attached table here? Access? SQL Server? MySQL? I'm
guessing the guy was using an ODBC driver, so the problem could be with the
driver.

Another possibility worth tracing: make sure you have SP8 for JET 4. Lots of
issues have been fixed (not specifically this one AFAIK). If you are not
sure, locate msjet40.dll (typically in windows\system32), right click and
choose Properties, and check the Version tab. If you don't see the 8 in
4.0.8xxx.0
then get SP8 from:
http://support.microsoft.com/gp/sp

Make sure you have the latest SP for your verson of Office also.
 
B

Bob Howard

Thanks Allen. My database is an Access 2000 backend. Actually, the
software I'm working on is an application package that can run on most any
level of software so long as it's Access 2000 (or later, or possibly the A2K
Runtime Library, which I also distribute). I don't want to place any other
restrictions on the users because most of them have severely limited
resources and won't have much capability to perform upgrades, etc. So I
need to stick with basics and implement a workaround (Dcount). So I don't
think I can go much further on this --- I truly appreciate all your help!
This application could never have gotten off the ground without all the help
I've obtained from this forum. Bob.
 
Top