Syntax for DCount Code

T

TESA0_4

Hi,

The following two DCount expressions are returning the correct values.

DCount("[HazID]", "tblHazReg", "[HazStat] Like 'ARCHIVED'")
DCount("[HazID]", "tblHazReg", "[QRID] = " & Me.txtQRID.Value)

However, what I want to do is combine the criteria from the two expressions
with an AND statement. I just don't seem to be able to get the syntax right.

Can anyone help me out?
 
B

bcap

DCount("[HazID]", "tblHazReg", "[HazStat] Like 'ARCHIVED' AND [QRID] = " &
Me.txtQRID.Value)
 
T

TESA0_4

Thanks bcap.
You answered my question. I don't understand why the DCount works with the
criteria recorded in the opposite order to what you advise? However, the main
thing is the function is now working in my code!!

bcap said:
DCount("[HazID]", "tblHazReg", "[HazStat] Like 'ARCHIVED' AND [QRID] = " &
Me.txtQRID.Value)

TESA0_4 said:
Hi,

The following two DCount expressions are returning the correct values.

DCount("[HazID]", "tblHazReg", "[HazStat] Like 'ARCHIVED'")
DCount("[HazID]", "tblHazReg", "[QRID] = " & Me.txtQRID.Value)

However, what I want to do is combine the criteria from the two
expressions
with an AND statement. I just don't seem to be able to get the syntax
right.

Can anyone help me out?
 
B

bcap

Not sure I understand your question.

These two statements are logically identical, it doesn't matter what order
you specify the criteria in:

DCount("[HazID]", "tblHazReg", "[HazStat] Like 'ARCHIVED' AND [QRID] = " &
Me.txtQRID.Value)
DCount("[HazID]", "tblHazReg", "[QRID] = " & Me.txtQRID.Value & " AND
[HazStat] Like 'ARCHIVED'")

Incidentally, why are you using the LIKE operator without any wildcards?
You might just as well use "=":

DCount("[HazID]", "tblHazReg", "[HazStat] = 'ARCHIVED' AND [QRID] = " &
Me.txtQRID.Value)


TESA0_4 said:
Thanks bcap.
You answered my question. I don't understand why the DCount works with the
criteria recorded in the opposite order to what you advise? However, the
main
thing is the function is now working in my code!!

bcap said:
DCount("[HazID]", "tblHazReg", "[HazStat] Like 'ARCHIVED' AND [QRID] = "
&
Me.txtQRID.Value)

TESA0_4 said:
Hi,

The following two DCount expressions are returning the correct values.

DCount("[HazID]", "tblHazReg", "[HazStat] Like 'ARCHIVED'")
DCount("[HazID]", "tblHazReg", "[QRID] = " & Me.txtQRID.Value)

However, what I want to do is combine the criteria from the two
expressions
with an AND statement. I just don't seem to be able to get the syntax
right.

Can anyone help me out?
 
T

TESA0_4

Hi,

I tried the expression DCount("[HazID]", "tblHazReg", "[QRID] = " &
Me.txtQRID.Value & " AND [HazStat] Like 'ARCHIVED'") and got a compile error
so I put in the expression as you typed it and it worked.

I must have made a typing error.

Why am I using 'Like'. Because I started off with a wildcard requirement
that has now been eliminated and had simply neglected to change to '='.

Thanks for you help.

bcap said:
Not sure I understand your question.

These two statements are logically identical, it doesn't matter what order
you specify the criteria in:

DCount("[HazID]", "tblHazReg", "[HazStat] Like 'ARCHIVED' AND [QRID] = " &
Me.txtQRID.Value)
DCount("[HazID]", "tblHazReg", "[QRID] = " & Me.txtQRID.Value & " AND
[HazStat] Like 'ARCHIVED'")

Incidentally, why are you using the LIKE operator without any wildcards?
You might just as well use "=":

DCount("[HazID]", "tblHazReg", "[HazStat] = 'ARCHIVED' AND [QRID] = " &
Me.txtQRID.Value)


TESA0_4 said:
Thanks bcap.
You answered my question. I don't understand why the DCount works with the
criteria recorded in the opposite order to what you advise? However, the
main
thing is the function is now working in my code!!

bcap said:
DCount("[HazID]", "tblHazReg", "[HazStat] Like 'ARCHIVED' AND [QRID] = "
&
Me.txtQRID.Value)

Hi,

The following two DCount expressions are returning the correct values.

DCount("[HazID]", "tblHazReg", "[HazStat] Like 'ARCHIVED'")
DCount("[HazID]", "tblHazReg", "[QRID] = " & Me.txtQRID.Value)

However, what I want to do is combine the criteria from the two
expressions
with an AND statement. I just don't seem to be able to get the syntax
right.

Can anyone help me out?
 

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

Similar Threads

Syntax Error in Query Expression 2
Help with DCOUNT syntax 2
DCount multiple criteria (date range and text field) 2
Dcount Problem 3
Dcount Criteria 2
DCount Function 2
DCount between dates 4
Odd DCount problem 6

Top