Right... now it works for some fields but not for others, this was the same
problem that I was having with the other code I was using. So, basically this
query should return all records if all search fields are left blank. If I
search only for the county field and leave the other fields blank it will
only return the the records with that county in. Below is the entire code
that I am using at the moment. is there any obvious mistakes??
SELECT Details.[Customer Name], Details.[Address 1], Details.[Address 2],
Details.[Address 3], Details.City, Details.County, Details.[Post Code],
Details.[Contact Name], Details.[Telephone Number], Details.[Mobile Number],
Details.[Fax Number], Details.[Current Supplier], Details.Group,
Details.[Group A/C Code], Details.Turnover, Details.[Sales Rep],
Details.Asian, Details.[Price - Pint], Details.[Price - Litre],
Details.[Price - 2 Litre], Details.[Qty - Pint], Details.[Qty - Litre],
Details.[Qty - 2 Litres], Details.Cream, Details.Bread, Details.Eggs,
Details.Notes, Details.Category, Details.[Linked to]
FROM Details
WHERE Details.category Like IIf(Forms![search Form]!category Is
Null,"*",Forms![search Form]!category) And Details.City Like
IIf(Forms![search Form]!city Is Null,"*",Forms![search Form]!city) And
Details.county Like IIf(Forms![search Form]!county Is Null,"*",Forms![search
Form]!county) And Details.category Like IIf(Forms![search Form]!category Is
Null,"*",Forms![search Form]!category) And Details.group Like
IIf(Forms![search Form]!group Is Null,"*",Forms![search Form]!group) And
Details.[current supplier] Like IIf(Forms![search Form]![current supplier] Is
Null,"*",Forms![search Form]![current supplier]);
Thanks again!!
Ofer said:
When you have a field that contains two name, you need to put it in square
brckets
And Details.[current supplier] Like IIf(Forms![search Form]![current
supplier]
Is Null,"*",Forms![search Form]![current supplier])
--
If I answered your question, please mark it as an answer. That way, it will
stay saved for a longer time, so other can benefit from it.
Good luck
:
WOW, thanks for the quick reply, it now works!!! Thanks for that!
One thing that I cant get right though is this part:
And Details.current supplier Like IIf(Forms![search Form]!current supplier
Is Null,"*",Forms![search Form]!current supplier)
As there is a space in the field it pops up an error message but if I delete
the space or use an underscore and I then run the query it pops up with an
enter parameter value window for the current suppleirs field. Any ideas??
:
Whet is the reason for the IsNull in this filter, if you want to return all
the records if the city is null, then try this
WHERE Details.City Like Nz(Forms![search Form]![city], "*")
Or
WHERE Details.City Like IIF(Forms![search Form]![city] Is Null, "*",
Forms![search Form]![city])
--
If I answered your question, please mark it as an answer. That way, it will
stay saved for a longer time, so other can benefit from it.
Good luck
:
I have a form (which has certain feilds from a table) that I can type in what
to search for from my table. I am using a parameter query which I did get
working but I changed it and I can't get it to work again.
The query is as follows:
WHERE ((Details.City)=Forms![search Form]!city Or
((Details.City)=Forms![search Form]!city) Is Null) **(I then have all the
other search fields repeated after this)**
If I don't have the null statement and I miss out one of the search fields
it doesn't return any records.
Have I typed the query in wrong or have I missed something (ps I am a
complete access novice - can you tell!!)
Thanks for any help!