Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 14th, 2005, 10:56 AM
Authorized User
Join Date: Oct 2003
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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,


Reply With Quote
  #2 (permalink)  
Old 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


How is the user choosing the parameters?


Reply With Quote
  #3 (permalink)  
Old 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.

Reply With Quote
  #4 (permalink)  
Old 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
Send a message via MSN to dmichael

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.
Reply With Quote
  #5 (permalink)  
Old 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.


Reply With Quote
  #6 (permalink)  
Old 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"
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Values In One Field lefty4080 Access 1 December 12th, 2007 08:59 AM
Multiple Field in an Event MRuzly Access VBA 6 September 5th, 2007 06:45 AM
multiple field search ddnk77872 PHP Databases 0 May 15th, 2007 02:55 AM
multiple checkbox store one field mateenmohd Classic ASP Basics 0 June 11th, 2006 01:39 AM
Multiple Joins in Multiple Table Search query pookster Access 4 September 23rd, 2004 03:04 PM

All times are GMT -4. The time now is 09:30 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.