473,408 Members | 1,676 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,408 software developers and data experts.

Passing Multi-Select field parameters to a query

Hi Everyone,

I've seen this question posted before and I believe the answer was to incorporate VB code somewhere into the form.

I am not familiar with VB and just wanted to know where to paste the code to.

I just have a simple query to pull all rows for any values selected in that multi-select field.

Form name is Search
List box name is List11
Query name is Form Query

I am running Access 2003 on Win2K


Thanks for the help!
Nov 12 '06 #1
3 5975
MMcCarthy
14,534 Expert Mod 8TB

I just have a simple query to pull all rows for any values selected in that multi-select field.

Form name is Search
List box name is List11
Query name is Form Query
With a multiselect listbox you need to use a command button (cmdSearch for this example).

I am assuming your form is bound to the query "Form Query"

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdSearch_Click()
  3. Dim val As Variant
  4. Dim strValues As String
  5.  
  6.   ' to get all the values selected into a string
  7.   strValues=""
  8.   For Each val In Me.List11.ItemsSelected
  9.     strValues = strValues & "'" & Me.List11.ItemData(val) & "',"
  10.   Next i
  11.  
  12.   ' remove the last comma
  13.   strValues = Left(strValues, Len(strValues)-1)
  14.  
  15.   Me.Filter = "[FieldNameAsList] IN (" & strValues & ")"
  16.   Me.FilterOn = True
  17.  
  18.   Me.Requery
  19.  
  20. End Sub
  21.  
  22.  
Nov 12 '06 #2
Thanks for the help. The code below should be placed in the On Click Event Procedure? Should I delete everything thats in there and paste the code below?

Thanks!


With a multiselect listbox you need to use a command button (cmdSearch for this example).

I am assuming your form is bound to the query "Form Query"

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdSearch_Click()
  3. Dim val As Variant
  4. Dim strValues As String
  5.  
  6.   ' to get all the values selected into a string
  7.   strValues=""
  8.   For Each val In Me.List11.ItemsSelected
  9.     strValues = strValues & "'" & Me.List11.ItemData(val) & "',"
  10.   Next i
  11.  
  12.   ' remove the last comma
  13.   strValues = Left(strValues, Len(strValues)-1)
  14.  
  15.   Me.Filter = "[FieldNameAsList] IN (" & strValues & ")"
  16.   Me.FilterOn = True
  17.  
  18.   Me.Requery
  19.  
  20. End Sub
  21.  
  22.  
Nov 13 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
Thanks for the help. The code below should be placed in the On Click Event Procedure? Should I delete everything thats in there and paste the code below?

Thanks!
If you mean what was created by the wizard I would guess yes. But for now just comment each line out by putting an apostrophe ' in front of each one in case you need to retrieve the code.
Nov 13 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Amr Mostafa | last post by:
Hello :) I'm trying to write a script that deals with a web service. I'm using NuSoap class. my question is : Can I pass some variables By Reference to the web service and get the result back...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
10
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
2
by: Curtis Justus | last post by:
Hi, I currently have a control that is on a form and I want to pass that exact instance of the control to another form (a child form that appears on a button click). The control has state,...
0
by: volx | last post by:
Hello all: What is the proper way to implement in MC++ a web service which accepts a multi dimensional array as a parameter to one of its methods? This does compile: double...
3
by: SQLScott | last post by:
I have looked all over and I cannot find an example or information on passing a multi-dimensional array. Well, that is not true. I found a close example in C++ but it didn't work when I...
4
by: entitledX | last post by:
Hi, I'm trying to use the HDF library to read a few HDF files that I need to process. The data in each file varies in rows, but the columns remain constant. Because of that, I had dynamically...
2
by: nleahcim | last post by:
Hi - I am working on writing a number of matrix manipulation functions. The most basic one was a printing algorithm - and it shows the problem I'm having. I'm passing it a pointer a mutidimensional...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.