Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to Count RowSources in a ComoBox? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    I have the following code that loads a combo box and it works OK

    How do I count the number of items in the combobox row source?

    Thanks, John

    <pre>strIDSQL = strIDSQL & _
    " FROM " & strTable & _
    " WHERE " & cboLookupSequence & _
    " LIKE '" & strZip & "*' " & _
    " ORDER BY " & strSort

    cboZip.RowSource = strIDSQL
    </pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How to Count RowSources in a ComoBox? (a2k (9.0.6926) SP-3 Jet 4.0 SP-

    Use the ListCount property.

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

    Re: How to Count RowSources in a ComoBox? (a2k (9.

    In addition, if using ListCount as recommended by HansV, don't forget that Columns Headings, if set to Yes (True), count too (unless there are no items listed in combo or listbox, in which case ListCount will equal zero). You can demonstrate this by creating 2 copies of same combobox on form, with same RowSource, and 2 unbound textboxes whose ControlSource property is something like:

    =[Combo1].ListCount (and)
    =[Combo2].ListCount

    Set Columns Headings to Yes on first combo and to No on second. Open form. The ListCount displayed for 1st combo will be one greater than that for 2nd combo (unless RowSource returns no records, then both will display zero for ListCount).

    HTH

  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to Count RowSources in a ComoBox? (a2k (9.0.6926) SP-3 Jet 4.0 SP-

    Thanks Hans & Mark for the command

    When I enter 14221 there are more than 1 zip and combo opens for operator selection.

    When I enter 14092 there is only 1 zip, and I
    Attached Files Attached Files

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How to Count RowSources in a ComoBox? (a2k (9.0.6926) SP-3 Jet 4.0 SP-

    In cboZip_AfterUpdate, Me.cboZip.Column(0) refers to the first column (since the index is zero-based) in the selected row of the combo box. But if there is only one item in the combo box, there is no selected row (you didn't give the user a chance to select one), so it's value is Null. So you must select a row in the code:
    <pre> If Me.cboZip.ListCount = 2 Then ' 1 for 1 zip found and 1 for column headers
    Me.cboZip.SetFocus
    Me.cboZip = Me.cboZip.ItemData(1)
    cboZip_AfterUpdate
    Exit Sub
    Else
    </pre>

    The instruction I inserted is in bold.

  6. #6
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to Count RowSources in a ComoBox? (a2k (9.0.6926) SP-3 Jet 4.0 SP-

    Thanks

Posting Permissions

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