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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox (ListBox.ListItem.Count)

Status
Not open for further replies.

JoPaBC

Technical User
Sep 26, 2017
85
CA
Hello,

I needed to update some calculations in an legacy program; I did my updates in one procedure, but when trying to compile the code, another procedure (see code below) gave an error message saying 'Method or data member not found' for 'ListItem' in this part 'lstSELINV.ListItems.Count' where lstSELINV is a ListBox (no changes there).

Code:
Private Sub cmdISEL_Click()
    Dim I
    On Error GoTo NAV1

    For I = 1 To lstSELINV.ListItems.Count
        Set lstSELINV.SelectedItem = lstSELINV.ListItems(I)
        If lstSELINV.SelectedItem = (Format(RSACCESS.Fields(0).Value, "000")) Then
            MsgBox "Invoice " & Format(RSACCESS.Fields(0).Value, "000") & " already added!"
            Exit Sub
        End If
    Next I

    Label18.Caption = Label18.Caption + 1

    Set lstmain2 = Me.lstSELINV.ListItems.Add(, , Format(RSACCESS.Fields(0).Value, "000"))
    cmdPREVIOUS_Click

NAV1:
End Sub

Any idea, please?
 
>where lstSELINV is a ListBox

Er, the error message is correct: a Vb6 Listbox does not have a ListItems property
 
... but it does have a ListCount property.
Keep in mind that ListBox's items start with 0, so if you start with 1 - you will miss first Item.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Thank you both for your input, you both are obviously right.
It looks like there is a problem with my Visual Studio (VB6) work/installation (it is running on Windows 11). When starting, it showed a lot 'Method'~'of Object '_' failed' messages.
It didn't load controls properly, it changed ListBox to PictureBox, doesn't recognize 'Form.StatusBar', etc.
So I had to manually add components and reinsert controls to get rid of error messages.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top