|
 |
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|
 |

July 14th, 2005, 10:56 AM
|
Authorized User
|
|
Join Date: Oct 2003
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Multiple field query PLUS
I want to create a SQL query for an Access database. I want the query to return records based on parameters entered by the user, unless no parameter for a particular field is entered, in which case it would return all records where that field exists.
Example (and I hope this is clear):
The database is a list of documents of county records, containing a document name, a county name, a document summary, etc. I want the user to be able to look up records either by county, or document name, or both. So the query form will request the user to enter a parameter in the appropriate field. If they enter no parameter, the query is to assume all records containing any value for that field are being requested.
Some one suggested the statement below, but I get an
"Invalid use of vertical bars in expression" error.
Anyone know the correct Access syntax?
select * from records
where dName like '%' || nvl('&dName','') || '%'
and county like '%' || nvl('&county','') || '%';
Thanks for your help,
Durwood
|

July 14th, 2005, 11:01 AM
|
Friend of Wrox
|
|
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Durwood,
How is the user choosing the parameters?
Kevin
dartcoach
|

July 14th, 2005, 03:17 PM
|
Authorized User
|
|
Join Date: Oct 2003
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It will be done in ASP. What I need is an example of how to query an Access database so that if no parameter is passed it assumes that all data in the field satisfies the query.
Thanks!
|

July 15th, 2005, 03:02 PM
|
Registered User
|
|
Join Date: Oct 2004
Location: Tupelo, MS, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Would something similar to this work?
If the fields queried were A, B, and C.
Select * from mytable
where ((mytable.A = form.A) OR isnull(form.A)) AND
((mytable.B = form.B) OR isnull(form.B)) AND
((mytable.C = form.C) OR isnull(form.C));
This way, if the Field on the form contains data it will be used to select data. If the field on the form is empty, that field is ignored for the purposes of the query.
Hope this helps.
:)
Darron
|

July 18th, 2005, 11:57 AM
|
Authorized User
|
|
Join Date: Oct 2003
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Bingo! That may well be it.
Thanks,
Durwood
|

July 26th, 2005, 09:08 AM
|
Authorized User
|
|
Join Date: Jun 2004
Location: , , USA.
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i think durwood would benefit by learning some VBA. I think it's bad practice to refer to forms in queries. Just think... The more forms you have, the more form specific queries you need. You should just have a couple of general information queries, and use VBA to filter them.
"Life is a Database"
|
Thread Tools |
Search this Thread |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |