Connecting Tech Pros Worldwide Help | Site Map

Listbox ListCount with RecordSet

Bruce
Guest
 
Posts: n/a
#1: Feb 26 '07
This is baffling to me. I'm using Access 2002. If I create an
unbound form and put an unbound listbox on it (List0) and then add the
following code to the Form_Load event:

Private Sub Form_Load()

List0.ColumnHeads = False
Set List0.Recordset = Nothing

MsgBox List0.ListCount

End Sub

Why do I get a message box saying ListCount is 1? Shouldn't it be 0?

Bruce

Rich P
Guest
 
Posts: n/a
#2: Feb 26 '07

re: Listbox ListCount with RecordSet


The listcount for an Access Listbox starts at 1. If you add one element
to the Rowsource of your listbox it will also display a count of 1. If
you add more than one element to the rowsource of your listbox it will
display the count of elements. I think when the count starts at 1 is is
called "non ordinal"? An Access collection object also starts at a
count of 1. But they (Microsoft) changed this convention in .Net, and
everything starts at a count of 0. More consistent this way, as you can
see.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
storrboy
Guest
 
Posts: n/a
#3: Feb 27 '07

re: Listbox ListCount with RecordSet


On Feb 26, 7:31 pm, Rich P <rpng...@aol.comwrote:
Quote:
The listcount for an Access Listbox starts at 1. If you add one element
to the Rowsource of your listbox it will also display a count of 1. If
you add more than one element to the rowsource of your listbox it will
display the count of elements. I think when the count starts at 1 is is
called "non ordinal"? An Access collection object also starts at a
count of 1. But they (Microsoft) changed this convention in .Net, and
everything starts at a count of 0. More consistent this way, as you can
see.
>
Rich
>
*** Sent via Developersdexhttp://www.developersdex.com***
Not sure if this changes after 97 as I have never tried it, but the
list count does read 0 when the RowsourceType is a Value List or a
Field List - it only seems to be 1 for a Table/Query. Probably much
like a query that returns no records, in query view it usually
produces one blank line.

Closed Thread