Laugh and point at the syntax moron (1 Viewer)

Kraj

Registered User.
Local time
Today, 01:00
Joined
Aug 20, 2001
Messages
1,470
Feel free to pick on me. I can't get syntax right. Ever. So when I can't figure it out I just try to find an example of what I want to do and use it as a guide. But I've not been able to find a single example (and I looked at a lot of threads and the *shudder* help files) of using "OR" in a DSum within a single field. Here is a simplified version of my statement:

=DSum("[Contribution_Amount]","tbl_CONTRIBUTION","[Employee_ID] =" & Forms!frmNew_Contribution!Employee_ID & " and [Special_Case] Is Null")

This works perfectly. I want it to look like this:

=DSum("[Contribution_Amount]","tbl_CONTRIBUTION","[Employee_ID] =" & Forms!frmNew_Contribution!Employee_ID & " and [Special_Case] = 'stringABC' or Is Null")

But this errors. And I've tried every combination of ' " () & # I can think of and everything errors, unless I completely set the OR apart into a new criteria, in which case it executes but produces results that are not what I'm trying to get. It also works if I add "= 'stringABC'" and remove the IsNull. I just can't seem to have both. Does anyone know how to write this properly?
 

FoFa

Registered User.
Local time
Yesterday, 19:00
Joined
Jan 29, 2003
Messages
3,672
OR [fieldname] IS NULL
 

FoFa

Registered User.
Local time
Yesterday, 19:00
Joined
Jan 29, 2003
Messages
3,672
Also be careful with both the AND and the OR in that criteria, use Parens to enclose them properly
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:00
Joined
Feb 19, 2002
Messages
43,346
So, the DSum() would look like:
=DSum("[Contribution_Amount]","tbl_CONTRIBUTION","[Employee_ID] =" & Forms!frmNew_Contribution!Employee_ID & " and ([Special_Case] = 'stringABC' or [Special_Case] Is Null"))

Field names are not transitive. They must be repeated for each condition.

Wrong:
If fld1 = a or b or c
Correct:
If fld1 = a or fld1 = b or fld1 = c
Alternate:
If fld1 In(a,b,c)
 

Kraj

Registered User.
Local time
Today, 01:00
Joined
Aug 20, 2001
Messages
1,470
That did it. Thanks very much. I think I tried it with repeating the field name and with parenthesis, but not with both at the same time. Or maybe I included the and within the paranthesis.

Thanks for the assistance!
 

Users who are viewing this thread

Top Bottom