Delete From ListBox

ddrew

seasoned user
Local time
Today, 19:09
Joined
Jan 26, 2003
Messages
911
Could someone show me how to do a 'Delete from ListBox' please. my listbox is populated, but I want to be able to put a button on the form, select a record from the listbox and press the button to delete that record from the list.

I should add that this is an unbound listbox so it needs to be removed from the listbox and the table that is populating it.

Listbox is List22 the table that populates it is 'tblShootingTasks'
 
How do you want to delete the record from the list - by deleting the record from your table or by not showing the record in the list?
 
How do you want to delete the record from the list - by deleting the record from your table or by not showing the record in the list?

Delete it from the table and then to requery the listbox, think I can do the requesry bit but not the delete from table (so much to learn!)
 
Code:
SELECT tblShootingTasks.IDTaskings, tblShootingTasks.ContactName, tblShootingTasks.ShootID, tblShootingTasks.Task
FROM tblShootingTasks
WHERE (((tblShootingTasks.ShootID)=[Forms]![frmEntries]![ShootDateID]) AND ((tblShootingTasks.Task)="1"))
ORDER BY tblShootingTasks.ContactName;
 
Try this in the button click event..
Code:
Private Sub yourButtonName_Click()
    If Me.List22.ItemsSelected.Count > 0 Then
        CurrentDB.Execute "DELETE * FROM tblShootingTasks WHERE tblShootingTasks.IDTaskings = " & Me.List22
        Me.List22.Requery
    Else
        MsgBox "No Item selected to be deleted, please select an entry to be deleted", vbInformation
    End If
End Sub
 
Superb, many thanksI vcan apply it to the other places I have to use it now!
 

Users who are viewing this thread

Back
Top Bottom