473,396 Members | 1,918 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,396 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 5973
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.