By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,156 Members | 1,071 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,156 IT Pros & Developers. It's quick & easy.

Deleting records using a multselect listbox

P: n/a
I am trying to adapt some code so that when I double click an entry in a
multi-select list box, the entry represented by that entry is deleted from
the table. The code I am trying sort of shows what I am trying to achieve,
but it doesn't work.

Dim db As Database

Dim qdf As QueryDef

Dim frm As Form

Dim lst As ListBox

Dim strSQL As String

Dim varItem As Variant

Set db = CurrentDb

Set frm = Forms!frmMyform

Set lst = frm!lboBulkContact

strSQL = "DELETE qryBulkEntryDiscard" _

& " WHERE ID = '"

For Each varItem In lst.ItemsSelected

strSQL = strSQL & Me!lboBulkContact.ItemData(varItem) & "';"

Set qdf = db.CreateQueryDef("", strSQL)


Next varItem


The list box is bound to the field ID which is a text field.

The error is 'Syntax error (missing operator) in query expression
qryBulkEntryDiscard where ID - '992343".

The code stops on the Setqdf = db.CreateQueryDef line.

Can anyone please point me to the right way of doing this?
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Hi Dixie

Try this function (beware word wrap):

Private Function DeleteWordFromList(theWord As String)

DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM tblWord WHERE WordId = '" & theWord &
DoCmd.SetWarnings True
End Function

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.