Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete selected items from listbox

Status
Not open for further replies.

jw5107

Technical User
Jan 20, 2004
294
US
I am trying to utilize a multi select listbox to select records and then delete all that has been selected...

Any suggestions on how to set this up or where I can find some examples - I have searching the formums for quite some time now...

Thanks in advance..!!
jw5107
 
Try an advanced search in the Access fora* with keywords:
delete listbox

==========================================
* Microsoft: Access Forms Forum: forum702
Microsoft: Access Modules (VBA Coding) Forum: forum705
Microsoft: Access Queries and JET SQL Forum: forum701
Microsoft: Access Reports Forum: forum703
Microsoft: Access Tables and Relationships Forum: forum700
Microsoft: Access Other topics Forum: forum181
 
How are ya jw5107 . . .

Here's a starter:
Code:
[blue]   Dim SQL As String, CBx As ComboBox, itm
   
   Set CBx = Me![purple][b][i]ComboboxName[/i][/b][/purple]
   
   For Each itm In CBx.ItemsSelected
      SQL = "DELETE [purple][b][i]PrimaryKeyName[/i][/b][/purple] " & _
            "FROM [purple][b][i]TableName[/i][/b][/purple] " & _
            "WHERE ([purple][b][i]PrimaryKeyName[/i][/b][/purple])=" & CBx.ItemData(itm) & ";"
      DoCmd.RunSQL SQL
   Next
   
   Me.requery
   CBx.Requery
   
   Set CBx = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .
 
Hi theAce !
I wonder which kind of ComboBox my be MultiSelect ;-)
Replace this:
CBx As ComboBox
with this:
CBx As ListBox

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV said:
[blue]I wonder which kind of ComboBox my be MultiSelect [wink][/blue]
None that I know of! Actually I took [blue]jw5107[/blue] meant a ListBox . . . [blue]I guess brain to hand only made it half way[/blue] [wink]

Thanks for the heads up! [thumbsup2]

Calvin.gif
See Ya! . . . . . .
 
jw5107 . . .

Corrected code:
Code:
[blue]   Dim SQL As String, LBx As ListBox, itm
   
   Set LBx = Me![purple][b][i]ListboxName[/i][/b][/purple]
   
   For Each itm In LBx.ItemsSelected
      SQL = "DELETE [purple][b][i]PrimaryKeyName[/i][/b][/purple] " & _
            "FROM [purple][b][i]TableName[/i][/b][/purple] " & _
            "WHERE ([purple][b][i]PrimaryKeyName[/i][/b][/purple])=" & LBx.ItemData(itm) & ";"
      DoCmd.RunSQL SQL
   Next
   
   Me.Requery
   LBx.Requery
   
   Set LBx = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top