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

Hi, Try

For Each Loop instead of For Loop

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

I see you set con = nothing, but where do you dim con? where do you set con?

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.