943,678 Members | Top Members by Rank

Ad:
Feb 16th, 2009
0

Deleting listview checked data using delete button

Expand Post »
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
   con.BeginTranserror.zip
   con.Execute "DELETE from Supplier where Supplier_Name='" & ListView1.ListItems(x).SubItems(1) & "'"
   ListView1.ListItems.Remove x
   con.CommitTrans
   End If
   Next
   con.Close
   Set con = Nothing
  End Sub
Reputation Points: 7
Solved Threads: 1
Posting Pro in Training
firoz.raj is offline Offline
415 posts
since Dec 2008
Feb 19th, 2009
0

Re: Deleting listview checked data using delete button

Hi, Try

For Each Loop instead of For Loop
Reputation Points: 44
Solved Threads: 101
Posting Pro
selvaganapathy is offline Offline
547 posts
since Feb 2008
Feb 20th, 2009
0

Re: Deleting listview checked data using delete button

Click to Expand / Collapse  Quote originally posted by firoz.raj ...
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
      con.Execute "DELETE from Supplier where Supplier_Name='" & ListView1.ListItems(x).SubItems(1) & "'"
   ListView1.ListItems.Remove x
   con.CommitTrans
   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
Reputation Points: 19
Solved Threads: 115
Nearly a Posting Virtuoso
cguan_77 is offline Offline
1,317 posts
since Apr 2007
Feb 21st, 2009
0

Re: Deleting listview checked data using delete button

I see you set con = nothing, but where do you dim con? where do you set con?
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Sql insert into
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: retrieving row with reference of Null value





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC