Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listcount returns correct value + 1

Status
Not open for further replies.

paradiso

Programmer
Apr 18, 2002
60
US
Friends,

In a form's VB module I populate a list box on the form's open event, based on the ID sent to it in OpenArgs. At certain points in the code I test to see how many items there are in the box. The LstActivities.ListCount property returns the actual count + 1.

The list box's RowSource query is based on a single table and involves a primary key, so I tried just casting that key to a long integer

SELECT CLng(TblEvents.EventID) AS EventID, TblEvents.EventName, ...

No change.

I also tried changing the query to an aggregate query, which, when I run it in the design grid comes up with the appropriate number of records like the normal query does, except it does not display the asterisk that invites a new record. Still the return is the actual value + 1.

So what gives? How can I get that listcount to reflect the number of records returned by the query?

thanks,
p
 
How are you determining the actual number of items in your listbox? The Listcount will always be +1 in relation to the List.Index, because the index starts at Zero.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Do you use header rows? I have found that Access sometimes includes the header row in the the ListCount.

What is even more disturbing is that it seems to do this inconsistently. Sometimes it includes the header row in the ListCount, sometimes it doesn't. If I remember correctly I had to write extra code just to check how Access felt like interpreting the header row that particular day. I think I did that by reading the first row in the first column: if it returned the column header I knew it was including the header in the ListCount, if it returned data it wasn't.
 
JoeAtWork said:
[blue]I have found that Access sometimes includes the header row in the the ListCount . . . . What is even more disturbing is that it seems to do this inconsistently.[/blue]
Nicrosoft said:
[blue][purple]ColumnHeads Property[/purple]

You can use the ColumnHeads property to display a single row of column headings for list boxes, combo boxes, and OLE objects that accept column headings. You can also use this property to create a label for each entry in a chart control. What is [purple]actually displayed as the first-row[/purple] column heading depends on the object's RowSourceType property setting.[/blue]

Calvin.gif
See Ya! . . . . . .
 
How are ya paradiso . . .

If you the [blue]Column Heads[/blue] property set to [purple]Yes[/purple] it is counted as a row . . .

Calvin.gif
See Ya! . . . . . .
 
And who is this Nicrosoft you quoted? Perhaps a N(icer)(M)icrosoft? [wink]

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
paradiso . . .

Hit submit too soon . . .
microsoft said:
[blue][purple]ListCount Property . . .[/purple]

If you set the [purple]ColumnHeads[/purple] property to Yes, [purple]the row of column headings is included in the number of rows returned by the ListCount[/purple] property. For combo boxes and list boxes based on a table or query, adding column headings adds an additional row. [purple]For combo boxes and list boxes based on a value list, adding column headings leaves the number of rows unchanged[/purple] (the first row of values becomes the column headings).[/blue]
A quick look in help would've resolved this for you!

Calvin.gif
See Ya! . . . . . .
 
Dear colleagues,

I'm a bit chastened, but very grateful for all your posts, and I hope others will benefit from this thread. I tend to go to my thick books on Access programming when I hit a snag, then I search Tek-Tips. Next time I'll check Help too before I call for assistance.

regards,
p
 
paradiso said:
[blue]I'm a bit chastened . . .[/blue]
Noooooooo don't be! Ya see we are the good guys! [thumbsup2]

Don't forget there's Access Help, VBE Help, and [blue]Context Sensitive Help[/blue].

With [blue]Context Sensitive Help[/blue] just put cursor on a property line & hit F1 . . . or in the VBE editor put the cursor on a word & hit F1 . . . [blue]takes you right there![/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top