Deleting Records from ListBox

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

I'm running this code to delete a record from a listbox, is there a
better way?

Private Sub Command4_Click()
Dim myID As Long, mySQL As String

myID = Me![List0]
mySQL = "DELETE * FROM AddModsQ " _
& "WHERE [ItemId] = " & Me![List0].Column(0) & ""
DoCmd.RunSQL mySQL
Me.List0.Requery

End Sub

Also I'm getting a prompt asking me if I want to delete this record,
anyway to replace or do away with this message?
Thanks
DS
 
Alter your code to this:

Private Sub Command4_Click()
Dim myID As Long
Dim mySQL As String

myID = Me.List0
mySQL = "DELETE * FROM AddModsQ " & _
"WHERE [ItemId] = " & Me![List0].Column(0)

CurrentDb.Execute mySQL, dbFailOnError
Me.List0.Requery

End Sub

R. Hicks
 
Ricky said:
Alter your code to this:

Private Sub Command4_Click()
Dim myID As Long
Dim mySQL As String

myID = Me.List0
mySQL = "DELETE * FROM AddModsQ " & _
"WHERE [ItemId] = " & Me![List0].Column(0)

CurrentDb.Execute mySQL, dbFailOnError
Me.List0.Requery

End Sub

R. Hicks

:

I'm running this code to delete a record from a listbox, is there a
better way?

Private Sub Command4_Click()
Dim myID As Long, mySQL As String

myID = Me![List0]
mySQL = "DELETE * FROM AddModsQ " _
& "WHERE [ItemId] = " & Me![List0].Column(0) & ""
DoCmd.RunSQL mySQL
Me.List0.Requery

End Sub

Also I'm getting a prompt asking me if I want to delete this record,
anyway to replace or do away with this message?
Thanks
DS
I tried it and got this error message on the Currentdb.execute line

too few parameters 1

Thanks
DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top