Can anyone tell me how should i delete listview checked data using
delete button. right now i got error object variable or with block
variable not set.

Private Sub Command3_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim x As Integer
For x = ListView1.ListItems.Count To 1 Step -1
If ListView1.ListItems(x).Checked = True Then
  <strong> con.BeginTrans
<p><a href="/images/attachments/1/error.zip">error.zip</a></p>

   con.Execute "DELETE from Supplier where Supplier_Name='" & ListView1.ListItems(x).SubItems(1) & "'"
   ListView1.ListItems.Remove x
   con.CommitTrans</strong>
   End If
   Next
   con.Close
   Set con = Nothing
  End Sub

Can anyone tell me how should i delete listview checked data using
delete button. right now i got error object variable or with block
variable not set.

Private Sub Command3_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim x As Integer

con.BeginTrans
For x = ListView1.ListItems.Count To 1 Step -1
If ListView1.ListItems(x).Checked = True Then
  [B]    con.Execute "DELETE from Supplier where Supplier_Name='" & ListView1.ListItems(x).SubItems(1) & "'"
   ListView1.ListItems.Remove x
   con.CommitTrans[/B]
   End If
   Next
   con.Close
   Set con = Nothing
  End Sub

i just re-arrange your code i put the con.begintrans before the for loop.. check if it will help

Private Sub cmdListView_CheckedRowDEL_Click()

'''''''Deleting Listview Checked Row Data using delete button'''''
'''''''Deleting Listview Checked Row Data using Connection Object like CN '''''''''''

Dim x As Integer

On Error GoTo Rollback_Err
''''''''''''''''
CN.BeginTrans
For x = ListView2.ListItems.Count To 1 Step -1
    If ListView2.ListItems(x).Checked = True Then
        CN.Execute "DELETE from tblCustomer where tblCustomer.CustNo=" & ListView2.ListItems(x).SubItems(5) & ""
        ListView2.ListItems.Remove x
    End If
    Next
CN.CommitTrans
''''''''''''''''''''''''

Exit Sub
Rollback_Err:
    Me.MousePointer = vbDefault
    Set rs = Nothing
    CN.RollbackTrans
    MsgBox Error$, 48, "Data Transaction Error."
'''''''''''''''''

End Sub

Edited 4 Years Ago by pyTony: code tags added

This article has been dead for over six months. Start a new discussion instead.