473,378 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Deleting records using a multselect listbox

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)

qdf.Execute

Next varItem

Me.lboBulkContact.Requery

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
1 1542
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
Me!lboList.Requery
End Function

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: flupke | last post by:
Hi, i'm having trouble with deleting elements from a list in a for loop ============== test program ============== el = print "**** Start ****" print "List = %s " % el index = 0 for line...
2
by: Lee-Anne Waters via AccessMonster.com | last post by:
Hi, would someone please help me with this problem. i have a list box that displays a persons various sub records. what i want to do is to be able to double click a list box record and have it...
1
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting...
3
by: Abra | last post by:
My C# application has a list (ListBox object), connected over a DataView to a dataset which corresponds to a table from a MySql database. I want to delete for example 4000-5000 rows from the table,...
1
by: jez123456 | last post by:
Hi, I have a windows form with a listbox control. My code all works correctly when deleting an item from the listbox except the last item. I get the following message when trying to delete the...
5
by: John Veldthuis | last post by:
My code works perfectly 100% when adding items to my ArrayList and updating the listbox. Works perfectly when deleting an item in the ArrayList when it is not the last entry but if it is the last...
6
by: gerbski | last post by:
Hi all, I am relatively new to ADO, but up to now I got things working the way I wanted. But now I've run into somethng really annoying. I am working in MS Access. I am using an Access...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
4
by: Bart Steur | last post by:
Hi, I'm writing an app to maintain products. The products are listed in a listbox and when I click a product in a listbox some info of that product is shown including a picture of the product. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.