A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Query based on multiple parameters - Access 2003



 
 
Thread Tools Display Modes
  #1  
Old May 24th, 2010, 07:14 PM posted to microsoft.public.access.queries
Pam
external usenet poster
 
Posts: 336
Default Query based on multiple parameters - Access 2003

I would like to create a query where the user can input 2 or more parameters
(part numbers), separated by comma and/or space and return information about
that part. I already have a query that accepts one parameter. Is there a
way to do this with more than one?

I have read some posts that say to use a table to serve up the paraments and
the user chooses one or more. However, a particular part or parts may not
yet be in the table as they are new or unknown.

Is there any way to do this without using an existing table but just accept
input from the user on the fly?

Thanks!
  #2  
Old May 24th, 2010, 07:21 PM posted to microsoft.public.access.queries
Bob Barrows
external usenet poster
 
Posts: 475
Default Query based on multiple parameters - Access 2003

Pam wrote:
I would like to create a query where the user can input 2 or more
parameters (part numbers), separated by comma and/or space and return
information about that part. I already have a query that accepts one
parameter. Is there a way to do this with more than one?

I have read some posts that say to use a table to serve up the
paraments and the user chooses one or more. However, a particular
part or parts may not yet be in the table as they are new or unknown.

Is there any way to do this without using an existing table but just
accept input from the user on the fly?


Here is a compilation of posts about how to deal with this issue:
There are two solutions for this problem listed in the following KB
article
(Q210530 - ACC2000: How to Create a Parameter In() Statement), found by
searching for the keywords "parameter list query" (no quotes) at
http://support.microsoft.com.

http://support.microsoft.com/suppor...s/Q210/5/30.ASP

The first solution uses Instr() to test the field values against the
list in
the parameter. The second involves dynamically creating a SQL statement
in
code.

Thanks to Paul Overway, here is a third solution, using the Eval
function:

WHERE (((Eval([Table]![Field] & " In(" &
[Forms]![Formname]![textboxname] &
")"))=True))

or, using a prompted parameter:

WHERE (((Eval([Table]![Field] & " In(" & [Enter List] & ")"))=True))


Thanks to Jeffrey A. Williams, here's a 4th solution:

If you don't mind adding a table to your database, and you're
comfortable
dealing with possible multi-user issues, this will perform better than
either of the solutions that involve running a function (Instr or Eval)
on
every row of your table:

Create a new table with two fields:

tblCriteria:
Criteria text
Selected boolean (yes/no)

Populate the table with your values and select a couple of items. Now
you
can use this table in your query as such:

Select * from table1
inner join tblcriteria
on table1.[your criteria field] = tblcriteria.criteria
where tblcriteria.selected = true

You can easily setup a form (or subform) that is bound to tblCriteria
and
allow the users the
ability of selecting which values they want.



Thanks to Michel Walsh, here's yet another way:

SELECT Table3.ConName, Table3.State, Table3.Zip
FROM Table3
WHERE "," &[list] & "," LIKE "*," & [ConName] & ",*"

with [param] some string like: '1,4,5,7'

note that there is no space after the comas.


It works simply. If AccountID is 45, clearly ',1,4,5,7,' LIKE
'*,45,*' returns false.
If AccountID is 4, on the other hand, ',1,4,5,7,' LIKE '*,4,*'
returns true.

So, you have, in effect, an IN( ) where the list is a parameter.


--
HTH,
Bob Barrows


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:23 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.