Syntax for DCount Code

  • Thread starter Thread starter TESA0_4
  • Start date Start date
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?
 
DCount("[HazID]", "tblHazReg", "[HazStat] Like 'ARCHIVED' AND [QRID] = " &
Me.txtQRID.Value)
 
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?
 
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?
 
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?
 
Back
Top