Connecting Tech Pros Worldwide Forums | Help | Site Map

Search Form

Eddie Holder
Guest
 
Posts: n/a
#1: Sep 29 '06
Hi Guys, I hope that someone will be able to help

I have a table containing data, lets say products.
I have a form with a text box which serves as the criteria for a query
to search the product name

I would like the form and the query to work as follows

If a leave the field blank on the form, it should return all the data
from the table
If I enter anyting on the form, I would like the form to return a
wildcard search result.

This is the formula I entered for the criteria in the query


IIf([Forms]![SearchForm]![PNAME] Is
Null,[Products]![ProductName],([Products].[ProductName]) Like
[Forms]![SearchForm]![PNAME])

Any idea how this would be possible or any other guidelines would
really be useful! the search form will hold around 10 fields with the
same functionality

Kind Regards,
Eddie Holder


Allen Browne
Guest
 
Posts: n/a
#2: Sep 29 '06

re: Search Form


Eddie, there are several ways to achieve what you need.

The most basic is to try to manipulate the query statement so the WHERE
clause contains something like this:
WHERE (([Forms]![SearchForm]![PNAME])
OR ([Products]![ProductName] = [Forms]![SearchForm]![PNAME]))

That gets very messy and inefficient when you add more items, so it is
probably better to build a filter from only the boxes where the user enters
a value. For details, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
It includes a sample database to download, so you can see how it works.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Eddie Holder" <eddie.holder@mousetraining.comwrote in message
news:1159538508.506903.318650@m73g2000cwd.googlegr oups.com...
Quote:
Hi Guys, I hope that someone will be able to help
>
I have a table containing data, lets say products.
I have a form with a text box which serves as the criteria for a query
to search the product name
>
I would like the form and the query to work as follows
>
If a leave the field blank on the form, it should return all the data
from the table
If I enter anyting on the form, I would like the form to return a
wildcard search result.
>
This is the formula I entered for the criteria in the query
>
>
IIf([Forms]![SearchForm]![PNAME] Is
Null,[Products]![ProductName],([Products].[ProductName]) Like
[Forms]![SearchForm]![PNAME])
>
Any idea how this would be possible or any other guidelines would
really be useful! the search form will hold around 10 fields with the
same functionality
>
Kind Regards,
Eddie Holder

Closed Thread