Question Delete Multiple Selected Records in a Table based on ListBox Multiple Selection (1 Viewer)

gstreichan

Registered User.
Local time
Today, 18:37
Joined
Apr 1, 2014
Messages
28
Dears,

I am stuck and have searched so much on the topic as there are many discussions about it but I can't seem to get it done.

I have a Table1 with 3 Columns: Name, Surname, ID (Unique)

I have a ListBox (List37) on a Form1 the List37 is with Multiple Select "Extended" and has 3 columns (Row Source on Table1).

What I want is to have OnClik event on a Button that allows user to delete Multiple Selected Records of List37 from the Table1.

In Summary:

Table1 has 3 Columns: Name, Surname, ID (Unique)
Form1 has a ListBox (List37) with 3 Columns and Extended Multiple Select Mode. List37Column(2) is the ID Number that I think is the one to be referenced to the Table1 for deleting all row from it.

Can you help me on this matter? I know it is simple, I got a code for deleting one line but not for multiple ones... :banghead:
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:37
Joined
May 7, 2009
Messages
19,245
you can't on OnClick event, because your are deleting a record from the table where your listbox is based.
put a command button and delete from there:
Code:
private sub button_click()
dim var as variant
if me.list37.ItemsSelected.Count > 0 then
    for each var in me.list37.itemsselected
        currentdb.execute "delete * from table1 where [id number] = " & me.list37.column(2, var)
    next
me.list37.requery
end if

end sub
 

gstreichan

Registered User.
Local time
Today, 18:37
Joined
Apr 1, 2014
Messages
28
Thank you so much Arnelgp. In fact I meant OnClick event of Button. It is very cool to have your quick reply. All the best!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:37
Joined
May 7, 2009
Messages
19,245
sorry, I overlook at your post #1, you do have a button in there.
 

Users who are viewing this thread

Top Bottom