Results 1 to 3 of 3

Thread: Still no luck

  1. #1
    Guest
    I'm still not having any luck.


    I'm grabbing text from four texboxes and adding it to a list view with four columns with the click of a button. What is the Syntax for checking if the data I'm about to add to the listview already exists? Here's my current code that adds data to my columns.

    Private Sub cmdAddToListView_Click()

    Set sitem = lstCustomers.ListItems.Add(, , txtFields(1).Text)

    sItem.SubItems(1) = txtFields(2).Text
    sItem.SubItems(2) = txtFields(3).Text
    sItem.SubItems(3) = txtFields(4).Text

    End Sub

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Code:
    Private Sub cmdAddToListView_Click() 
    
      On Error Resume Next
      Set sitem = lstCustomers.ListItems.Add(, , txtFields(1).Text) 
      If Err.Number = 0 Then
        sItem.SubItems(1) = txtFields(2).Text 
        sItem.SubItems(2) = txtFields(3).Text 
        sItem.SubItems(3) = txtFields(4).Text 
      Else
        MsgBox "Already Exists"
      End If
    
    End Sub

  3. #3
    Guest
    Hello,

    I did get this to work, so give it a try.

    Code:
    Private Sub cmdAddToListView_Click()
      
      Dim sItem As ListItem
      Dim itmFound As ListItem
    
      Set itmFound = lstCustomers.FindItem(txtFields(0).Text, lvwText, , lvwPartial)
    
      If itmFound Is Nothing Then
        Set sItem = lstCustomers.ListItems.Add(, , txtFields(0).Text)
        sItem.SubItems(1) = txtFields(1).Text
        sItem.SubItems(2) = txtFields(2).Text
        sItem.SubItems(3) = txtFields(3).Text
      Else
        MsgBox "Item already listed"
      End If
    
    End Sub
    Hope this helps,

Posting Permissions

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



Click Here to Expand Forum to Full Width