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

Multiselect Query Parameters - Allowing All States When No Selection Has Been Made

I'm trying to design a query in Access 2007 that will select clinicians based upon a list of desired counties and specialties. The query receives its parameters from a form where the searcher may choose their desired counties and specialties from two multiselect menus. At present, it works wonderfully assuming that selections have been made. However, I am trying to design it such that if no selection is made, the query will show all specialties and/or counties. I found a nifty little demo that includes just such a function here:

http://www.blueclaw-db.com/multi_select_parameter_form.htm

They use this simple command in their WHERE statement:

in (select state from t_states) or dlookup("Count(state)","T_States")=0

Where 'state' is a field of the table, 'T_States,' which holds the selected parameters.

This works beautifully in their demo, but I can't get it to work in my query for one, let alone two, multiselect parameters. The query simply returns empty - no error messages. Any ideas?

I know that a subquery would be an alternative option, but I am rather new to their use and am unclear how I should design one to suit my needs here.
Aug 6 '10 #1
3 1548
Steven Kogan
107 Expert 100+
That is quite nifty.

For this to work you need to use VBA to properly populate the table that contains the selected parameters. You should be able to verify that the table contains what you expect to. Once that part works, then you should be able to adapt the where statement to your app.

Generic code to populate the temporary table and run the query is:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Run_Query_Click()
  2. Dim x As Long
  3. '
  4. ' clear out old values
  5. '
  6. docmd.setwarnings false
  7. DoCmd.RunSQL ("Delete * from TempTable")
  8. '
  9. For x = 0 To Me.Parameter_List.ListCount - 1
  10.     If Me.Parameter_List.Selected(x) = True Then
  11.         DoCmd.RunSQL ("Insert into TempTable (Parameter) values ('" & _
  12.             Me.Parameter_List.ItemData(x) & "')")
  13.     End If
  14. Next x
  15. docmd.setwarnings true
  16. '
  17. ' open query
  18. '
  19. DoCmd.OpenQuery "MyQuery"
  20. End Sub
Aug 6 '10 #2
NeoPa
32,556 Expert Mod 16PB
A subquery wouldn't be an alternative Andrew, as the solution you showed includes one as well.

It may be helpful at this stage to post the whole of the related part of the WHERE clause. Your snippet is frustratingly incomplete.

If I assume for now that you are filtering the field [State] from the table [T_States] then we might try an alternative of :
Expand|Select|Wrap|Line Numbers
  1. WHERE (([State] In(SELECT [State]
  2.                    FROM   [T_States]))
  3.    OR  (DCount('*','[T_States]','[State]=''' & [State] & '''')=0))
Welcome to Bytes!
Aug 7 '10 #3
hype261
207 100+
Generally in this situation I dynamically build the sql where statement on the fly. When the user clicks the search button I check to see if the combo boxes or text boxes are NULL or Empty. If they aren't then I append to the SQL statement. You have to keep track of how many things have been added to see if you need to add an AND/OR statement, but this has worked out for me in the past.
Aug 7 '10 #4

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

Similar topics

1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
0
by: Amelyan | last post by:
Root > Parent > Current Can sitemap control loaded from Web.sitemap be enabled to automatically maintain query parameters of previous node? E.g. when user clicks Parent, instead of just...
5
by: ric_deez | last post by:
Hi there, I would like to create a simple search form to allow users to search for a job number based on a number of parameters. I think I understand how to use parameteres associated with Stored...
4
by: amorphous999 | last post by:
I am running Access 2002. I have some reports I would like to be able to run from VBA or interactively. The reports use queries with parameters. When the user runs the report, the parameter...
6
by: Michael R | last post by:
Please help me with this. I have a form in which I would like to present results from a CrossTab query in a subform. I don't need the query to be bounded to a master field. Also, I have a...
6
by: sunil | last post by:
I have a button named Button1, and I wrote an event handler for the OnClick event. protected void Button1_Click(object sender, System.EventArgs e) { this.Response.Redirect("Default.aspx?q=" +...
5
by: dana1 | last post by:
Hello Experts! Does anyone know if there is a way to set the values of query parameters from VBA for a report's recordsource? (i.e., I want to set the values of the parameters and NOT have the...
3
hyperpau
by: hyperpau | last post by:
Hi there guys! I have a Form where there are three comboboxes. This comboboxes are used as references for the parameter of 3 fields in a query. when I hit a command button in my form, it opens...
17
by: NeoAlchemy | last post by:
I am starting to find more web pages that are using a query parameters after the JavaScript file. Example can be found at www.opensourcefood.com. Within the source you'll see: <script...
2
by: raaman rai | last post by:
i have 3 drop dropdown box which is used for searching my database. Either one of them can be selected to perform the search but if none of them is selected it will give an error. Well in reference...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
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...

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.