IIF(Dcount...syntax problem

G

Guest

HELP! I am trying to create a query criteria that returns specific records
based on specific criteria IF there are records to display meeting that
criteria - otherwise display ALL records without any criteria

I have a table called tblproperties - one field is {County] - when I query
for a specific county, for example "OCEAN" then I want to see all records
that satisfy that criteria...but if there are NO records with OCEAN in the
[County] Field, then I want to see ALL RECORDS regardless of the county.

Here's what I have in the Query on the Criteria row for the County field :
IIf((DCount("[County]","tblProperties","[County]='Ocean'")>0),"Ocean",Like
"*")

Something is wrong with the Like "*" expression - can you assist and
correct my syntax?
 
F

fredg

HELP! I am trying to create a query criteria that returns specific records
based on specific criteria IF there are records to display meeting that
criteria - otherwise display ALL records without any criteria

I have a table called tblproperties - one field is {County] - when I query
for a specific county, for example "OCEAN" then I want to see all records
that satisfy that criteria...but if there are NO records with OCEAN in the
[County] Field, then I want to see ALL RECORDS regardless of the county.

Here's what I have in the Query on the Criteria row for the County field :
IIf((DCount("[County]","tblProperties","[County]='Ocean'")>0),"Ocean",Like
"*")

Something is wrong with the Like "*" expression - can you assist and
correct my syntax?

Like comes first. And you can use the * in the DCount as you are
counting [County] = 'Ocean' and not trying to return the data in the
County field.

Like IIf((DCount("*","tblProperties","[County]='Ocean'")>0), "Ocean",
"*")
 
G

Guest

Hi MaureenKLM,

This syntax works for me.
Try this.

Like
(IIf((DCount("[County]","tblProperties","[County]='Ocean'")>0),"Ocean","*"))))
 
G

Guest

Many Thanks! It worked!

fredg said:
HELP! I am trying to create a query criteria that returns specific records
based on specific criteria IF there are records to display meeting that
criteria - otherwise display ALL records without any criteria

I have a table called tblproperties - one field is {County] - when I query
for a specific county, for example "OCEAN" then I want to see all records
that satisfy that criteria...but if there are NO records with OCEAN in the
[County] Field, then I want to see ALL RECORDS regardless of the county.

Here's what I have in the Query on the Criteria row for the County field :
IIf((DCount("[County]","tblProperties","[County]='Ocean'")>0),"Ocean",Like
"*")

Something is wrong with the Like "*" expression - can you assist and
correct my syntax?

Like comes first. And you can use the * in the DCount as you are
counting [County] = 'Ocean' and not trying to return the data in the
County field.

Like IIf((DCount("*","tblProperties","[County]='Ocean'")>0), "Ocean",
"*")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top