Help - Updating table entries selected in Listbox

DiverGuy

Registered User.
Local time
Today, 00:45
Joined
Jun 10, 2007
Messages
17
I'm trying to use the value selected in a combobox to update the selected
items in a listbox. Running into difficulty and all of my local resources
were unable to help. Here's what we're working with:

  • A table called tblFileList.
  • A table called tblPerformers
  • A query called qryFileList that pulls all of the data from tblFileList.
  • A form with
    a multi-select listbox called listboxFileList
    a combobox called cboPerformer
    and a button called cmdUpdate.

The listbox is populated from the query. The combobox is populated from
tblPerformers.

The goal is to be able to select, say, ten files from the list displayed in
the listbox, select a name from the combobox, click the Update button, and
the Performer field in tblFileList will be updated for those ten files.

I have started an UPDATE statement in the click event for the cmdUpdate
button:
Dim i as variant
For each i in Me.listboxFileList.ItemsSelected
'Nothing is currently in the For..Each statement
Next

Dim strSQL as String
strSQL = "UPDATE tblFileList SET tblFileList.Performer = ' " &
Me.cboPerformer.Value & " ' WHERE XXXXXXXX

DoCmd.RunSQL strSQL​

I'm stumbling on the part above indicated by XXXXXXX. Can anyone tell me
how to reference or specify only the files selected in the listbox and update
them in the table?

Any help will be appreciated.

Thanks.
 
Within your loop, build a string variable containing the selected items. It would look like this when it's done:

12, 24, 35, 55

Then your second line becomes

Me.cboPerformer.Value & " WHERE FieldName In(" & XXXXXXXX & ")"

If the data type of that field is text in the table, you'd have to surround each value with single quotes.
 

Users who are viewing this thread

Back
Top Bottom