#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    44
    Rep Power
    13

    Error with command button


    I have 2 command buttons 1 that add's to a list that goes like:

    Code:
     Private Sub Command1_Click()
    lstwindows4.AddItem Text1.Text
    Text1.Text = ""
    End Sub
    Which works fine and does what i want - but I have another command button which when clicked should delete an entry from the list if selected:

    Code:
     Private Sub Command2_Click()
    
    ty = lstwindows4.ListCount
    For ber = 0 To ty - 1
    lstwindows4.ListIndex = ber
    If lstwindows4.Text = Text2.Text Then
    lstwindows4.RemoveItem ber
    Text2.Text = ""
    Exit Sub
    End If
    Next ber
    Text2.Text = ""
    End Sub
    it does not seem to delete from the list?

    any help is appreciated

  2. #2
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    Try something like this:
    Code:
        cnt = lstListName.ListCount
        For cntr = 0 To lstListName.ListCount - 1
            If txtTextField = lstListName.List(cntr) Then
                lstListName.RemoveItem cntr
                txtTextField = vbNullString
                Exit Sub
            End If
        Next
    This will effectively remove an entry from a listbox where it matches the text field value.

IMN logo majestic logo threadwatch logo seochat tools logo