Dcount criteria coding problem

W

WCDoan

I'm trying to do a count of the number of animals for a specific owner. It
worked fine until I tried to add the AnimalDeceased and AnimalMoved criteria.
I've tried all kinds of combinations, but I haven't been able to find the
right one. Could someone please show me what this should look like. The
criteria would be:

OwnerID_AnimalTbl = Me.OwnerID and
AnimalDeceased = False and
AnimalMoved = False

CountOfAnimals = DCount("*", "tblAnimals", "[OwnerID_AnimalTbl] = &
Me.OwnerID AND [AnimalDeceased] = False AND [AnimalMoved] = False")

Thanks,
RandyM
 
A

Allen Browne

Concatenate the value from the form into the 3rd string:

DCount("*", "tblAnimals", "([OwnerID_AnimalTbl] = " & Me.OwnerID &
") AND ([AnimalDeceased] = False) AND ([AnimalMoved] = False)")

If [OwnerID_AnimalTbl] is a Text type field, you need extra quotes:
DCount("*", "tblAnimals", "([OwnerID_AnimalTbl] = """ & Me.OwnerID &
""") AND ([AnimalDeceased] = False) AND ([AnimalMoved] = False)")

If it is a Number type field, just make sure it is not Null.

For more info on how to build the 3rd argument for these functions, see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html
 
W

WCDoan

Thanks Allen, that did it!
Randy M

Allen Browne said:
Concatenate the value from the form into the 3rd string:

DCount("*", "tblAnimals", "([OwnerID_AnimalTbl] = " & Me.OwnerID &
") AND ([AnimalDeceased] = False) AND ([AnimalMoved] = False)")

If [OwnerID_AnimalTbl] is a Text type field, you need extra quotes:
DCount("*", "tblAnimals", "([OwnerID_AnimalTbl] = """ & Me.OwnerID &
""") AND ([AnimalDeceased] = False) AND ([AnimalMoved] = False)")

If it is a Number type field, just make sure it is not Null.

For more info on how to build the 3rd argument for these functions, see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

WCDoan said:
I'm trying to do a count of the number of animals for a specific owner. It
worked fine until I tried to add the AnimalDeceased and AnimalMoved
criteria.
I've tried all kinds of combinations, but I haven't been able to find the
right one. Could someone please show me what this should look like. The
criteria would be:

OwnerID_AnimalTbl = Me.OwnerID and
AnimalDeceased = False and
AnimalMoved = False

CountOfAnimals = DCount("*", "tblAnimals", "[OwnerID_AnimalTbl] = &
Me.OwnerID AND [AnimalDeceased] = False AND [AnimalMoved] = False")

Thanks,
RandyM
 

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