Delete selected (treeview) rows from data table in Visual basic 6.0


How to delete selected items from a data table (Access) in Visual basic 6.0 ? Users can select the item using a list view control.

Get the count of selected items first

For k = 1 To ListView_Slaes.ListItems.count
If ListView_Slaes.ListItems(k).Checked = True Then
selCount = selCount + 1
End If
Next

Get selected items deleted

Dim t
If selCount > 0 Then

For C = 1 To Me.ListView_Slaes.ListItems.count
top:

Set itmX = Me.ListView_Slaes.ListItems(C)
If itmX.Checked = True Then

takesql = “select * from stockmovement where itemname = ‘” & Trim(itmX.SubItems(1)) & “‘ ”
t = “And OpStock = ” & Val(Trim(itmX.SubItems(2)))
takesql = takesql + t
Set rs = MedicalShop.OpenRecordset(takesql)
If rs.RecordCount > 0 Then
rs.Delete
End If
End If
Next C
Else
MsgBox “Please select an ordered item(s) to remove”, vbInformation, “Selection error”
End If

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.