• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 930
  • Last Modified:

Row Count for List Box on Form

Is there an easy way to get the number of rows in a list box on a form?  This is Access 97.  I have a listbox that dynamically updates with form filters and want to display the number of rows for each filter.  Is there an easy way to do it?  I don't want to recreate the SQL (list box source) in VBA.
Thanks,

mv
0
Michael Vasilevsky
Asked:
Michael Vasilevsky
1 Solution
 
flavoCommented:
Here';s some code to do it

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset(Me.List1.RowSource)

If Not rs.EOF Then
    rs.MoveLast
End If
MsgBox rs.RecordCount

rs.Clone
Set rs = Nothing
0
 
harfangCommented:
The property is called ".ListCount", available for combos and boxes. You can retrieve any data from them with the .Column() property, which has an optional row parameter.
Example (immediate pane)

    ? Forms(0)!lstMyList.ListCount
    ? Forms(0)!lstMyList.Column(1, 23)

Good Luck
0
 
Gustav BrockCIOCommented:
Well, you need to take into account if you show column heads for this listbox as these will count for one row:

  lngListCount = Me!lstYourListbox.ListCount - Abs(Me!lstYourListbox.ColumnHeads)

/gustav
0
 
itauspineCommented:
Thanks Gustav was a great help to me
0
 
Gustav BrockCIOCommented:
After 9½ years. Thanks!

/gustav
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now