I was wondering what I have to do to get the selections in a multi select list box to show up in a query. Just the plain list box shows up just fine with one selection, but when I changed the multi select property to Extended, it wouldn't pull across into the query.
Any thoughts on this would be greatly appreciated.
Thanks for the reply.
That would be great. I don't know much about coding, but I am learning. I don't understand it. The plain list box works fine, but when you make it a multi select listbox, nothing works.
I use the following code to pass selected items from a multi-select list box to an query created on the fly via SQL. I got this code from someone else but have added comments in the code where I know what it does.
The listbox is called lstRecords and is poluated by the results of a query.
The SQL does the following. Updates the Authorised field in the Orders table and set it to True where the OrderID matches one selected in the listbox.
The second does a similar thing for the DateAuthorised field but this time it populates it with the contents of a field from the form.
You turn the warnings off so that it doesn't prompt you to confirm updating the records, and then you turn them back on again for future use.
On Error GoTo ErrUpdate
Dim strCriteria As String ' Declare the Variables
Dim varItem As Variant
' Add all items selected in the listbox to the strCriteria variable with a , between each item
For Each varItem In Me.lstRecords.ItemsSelected
strCriteria = strCriteria & "," & Me!lstRecords.ItemData(varItem)
In the code below I have created a table "TBL_delivery_Job_numbers" that I add the job number(s) selected on the list box, I run the query "QRY_Delivery_Clear_Table" to empty the table before use (it's a delete query).
I use it so that users can select which jobs are being sent on a delivery note to the customer. (the table is linked to a report)
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim tdf As DAO.TableDef
Dim rst As DAO.Recordset
Dim varitm As Variant
Dim ctl As Control
Set db = CurrentDb()
Set ctl = Me.LST_Active_jobs
Set qdf = db.QueryDefs("QRY_Delivery_Clear_Table")