Multiple Selection List Box as Critera for Query

Jameo

Active Member
Joined
Apr 14, 2011
Messages
270
Hi all, I have a form that filters a query. From that form there are multipe listboxes.

At the moment, in my query, I filter the results using the following in the query criterea

i.e.

[forms]![search]![cboarea]
etc. etc.

However, I would now like to add amultiple selection list box, instead of one of the combo boxes. After scanning around on the web it has become apparent that you can not simply use a list box using the above form criterea. I have found a couple of examples:

Code:
Option Compare Database
Option Explicit
 
Private Sub Command2_Click()
 
   Dim Criteria As String
   Dim i As Variant
 
   ' Build criteria string from selected items in list box.
   Criteria = ""
   For Each i In Me![List0].ItemsSelected
      If Criteria <> "" Then
         Criteria = Criteria & " OR "
      End If
      Criteria = Criteria & "[CustomerId]='" _
       & Me![List0].ItemData(i) & "'"
   Next i
 
   ' Filter the form using selected items in the list box.
   Me.Filter = Criteria
   Me.FilterOn = True
 
End Sub

But this does not seem to work for me. Bear in mind, that as well as selecting information from the list box, I still need to include the criterea from my other combo boxes.

http://support.microsoft.com/kb/135546 seems to be the most thourgh explanation out there, but I must admit I am a bit stuck.

Any help you can provide would be hugely appreciated. Many thanks
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,224,574
Messages
6,179,626
Members
452,933
Latest member
patv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top