Results 1 to 2 of 2

Thread: ListView Checkbox Click Question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2001
    Posts
    759

    ListView Checkbox Click Question

    Hi Everyone,

    Is there an easier way of doing this? Sometimes when this code runs I get an error: Object block or with variable block not set. Other times it runs just fine. Anyways, what I am trying to do is get a sql statement to run when a user selects or deselects any check box in the ListView. I can't seem to figure out how to get it to work without looping through the ListView each time. I would appreciate any help. Thanks.

    Code:
    Private Sub lvwHistory_ItemCheck(ByVal Item As MSComctlLib.ListItem)
        Dim objItem As ListItem
        
        For Each objItem In lvwHistory.ListItems
                    
            If objItem.Checked = True Then
                mcnAP.Execute "UPDATE DateRegister SET Void = Yes WHERE ID = " & objItem.Tag & ""
            Else
                mcnAP.Execute "UPDATE DateRegister SET Void = No WHERE ID = " & objItem.Tag & ""
            End If
        
        Next
    
    End Sub

  2. #2
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    The Netherlands
    Posts
    403
    By adding this if you shouldn't get the error I think
    VB Code:
    1. Private Sub lvwHistory_ItemCheck(ByVal Item As MSComctlLib.ListItem)
    2.     Dim objItem As ListItem
    3.    
    4.     For Each objItem In lvwHistory.ListItems
    5.         If Not objItem Is Nothing Then
    6.             If objItem.Checked = True Then
    7.                 mcnAP.Execute "UPDATE DateRegister SET Void = Yes WHERE ID = " & objItem.Tag & ""
    8.             Else
    9.                 mcnAP.Execute "UPDATE DateRegister SET Void = No WHERE ID = " & objItem.Tag & ""
    10.             End If
    11.         End If
    12.     Next
    13. End Sub
    There are 10 types of people, those who understand binary and those who don't

    http://merlijn.beyonix.net

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