Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    counting field in a list box (Access 2000)

    This may be a foolish request but it was a reguest made to me so here goes.... I have a listbox on a form called
    lstsearch in the list box is a heading called countryname. This form is a search form which allows the user to type different criteria in text boxes on the form (like countryname, cityname etc.). Based on what the user types in the form it gives the user a result in the list box called lstsearch. The user would like a total of the country names that are listed in the list box. SO it would be a total of the field called countyname in the list box called lstsearch. Or basically a total of the results in the list box. Is this possible? Thanks...

  2. #2
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: counting field in a list box (Access 2000)

    Try the Listcount property.
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  3. #3
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: counting field in a list box (Access 2000)

    You can use a function like this example:

    Private Function GetListCount() As Long

    With Me.Listbox1
    If .ListCount > 0 Then
    GetListCount = .ListCount - 1 'Headings count
    Else
    GetListCount = 0 'Headings don't count if no items listed!!
    End If
    End With

    End Function

    If you just want to display the list count in a textbox, you can use this expression as ControlSource in an unbound textbox:

    =IIf([ReportListbox].[list]-1,0)

    Note if the listbox has column headings, the headings count in number returned by ListCount property. If not using column headings, modify examples accordingly (you won't need to subtract 1 from ListCount). If no records listed in listbox, ListCount returns 0 (which is why you need the conditional statements if using column headings, so you don't get "-1" if no records listed.)

    HTH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •