Delete selected item from list box

HelpMoses76

Member
Local time
Yesterday, 23:57
Joined
Sep 17, 2020
Messages
45
del.JPG


I am trying to write a piece of code that works on button click and deletes a selected row from the Table . Not sure how I can reference the entire row. ID is the primary key in the table . Any ideas ?
 
Sorry, I meant the column number in the listbox properties.
 
Okay, for a non-multi select Listbox, you might be able to do something like this:
Code:
Dim strSQL As String
If MsgBox("Are you sure you want to delete this item?",vbQuestion+vbYesNo,"Confirm!")=vbYes Then
    strSQL = "DELETE FROM TableName WHERE ID=" & Me.ListboxName
    CurrentDb.Execute strSQL, dbFailOnError
End If
Hope that helps...
 
Okay, for a non-multi select Listbox, you might be able to do something like this:
Code:
Dim strSQL As String
If MsgBox("Are you sure you want to delete this item?",vbQuestion+vbYesNo,"Confirm!")=vbYes Then
    strSQL = "DELETE FROM TableName WHERE ID=" & Me.ListboxName
    CurrentDb.Execute strSQL, dbFailOnError
End If
Hope that helps...

Thank you so much for taking the time to reply . However it gives me an error on the last statement

CurrentDb.Execute strSQL, dbFailOnError . I wonder if I have to do some kind of variable declaration.
 
Thank you so much for taking the time to reply . However it gives me an error on the last statement

CurrentDb.Execute strSQL, dbFailOnError . I wonder if I have to do some kind of variable declaration.
What was the error message?
 
You did change the table and listbox names to match yours, didn't you :unsure:
 
You did change the table and listbox names to match yours, didn't you :unsure:
And the Field's Name too please (in case it's called other than just "ID").
 
I might say "need" is a strong word. :)
Well I was not sure it was mandatory as you had not used it, but I always have not knowing any better? , so I had to check with that link?

Edit: In fact that link says [table.*] is optional ??
 

Users who are viewing this thread

Back
Top Bottom