Deleting listview checked data using delete button

Reply

Join Date: Dec 2008
Posts: 292
Reputation: firoz.raj is an unknown quantity at this point 
Solved Threads: 1
firoz.raj firoz.raj is offline Offline
Posting Whiz in Training

Deleting listview checked data using delete button

 
0
  #1
Feb 16th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 509
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 88
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: Deleting listview checked data using delete button

 
0
  #2
Feb 19th, 2009
Hi, Try

For Each Loop instead of For Loop
KSG
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 1,101
Reputation: cguan_77 has a little shameless behaviour in the past 
Solved Threads: 91
cguan_77's Avatar
cguan_77 cguan_77 is online now Online
Veteran Poster

Re: Deleting listview checked data using delete button

 
0
  #3
Feb 20th, 2009
Originally Posted by firoz.raj View 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

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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Deleting listview checked data using delete button

 
0
  #4
Feb 21st, 2009
I see you set con = nothing, but where do you dim con? where do you set con?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC