Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coding for Multiple Conditions in Domain Aggregate Functions

Status
Not open for further replies.

bhujanga

Programmer
Oct 18, 2007
181
US
I'm trying to make a control on a form dependent on a DSUM value and cannot seem to get the code right for multiple conditions.
If I code this:
=DSum("[grams Active]","Extractions","[Retired] = -1")
It works fine.

If I code this:
=DSum("[grams Active]","Extractions","[Extraction Type] = 'Med (Clean)'")
It also works fine.

But if I try to use both conditions like this:
=DSum("[grams Active]","Extractions","[Extraction Type] = 'THC-Med (Clean)' and [Retired] = -1")
It returns no value.
It doesn't report any kind of problem, the control just goes blank. (There are qualifying records and none that have nulls in the [grams active] field.)
Is there something wrong with this syntax? I can't find any examples on line that have "and"s or "or"s in them.
Thanks.
 
True, but that's not the problem. I just inadvertently mixed that up when I was putting together the question (I'm trying to do a similar thing for various Extraction Types. In the code I have tried taking the whole statement and deleting one half or the other and regardless of which half I delete it then works. I've also tried it with other conditions, and no matter what I do as soon as I try combining conditions it fails, so it would seem something is amiss with that syntax.
Thanks.
 
Try create a query that mimics your DLookup() with SQL like:

SQL:
SELECT Sum([grams Active]) As TheSum FROM Extractions WHERE [Extraction Type] = "THC-Med (Clean)" and [Retired] = -1

Duane
Hook'D on Access
MS Access MVP
 
Try

Code:
([Extraction Type] = 'THC-Med (Clean)') AND ([Retired] = -1)

See Ya . . .

Be sure to see FAQ219-2884 Worthy Reading! [thumbsup2]
Also FAQ181-2886 Worthy Reading! [thumbsup2]
 
Thanks for your help. Oddly, I tried putting the parenthesis into one of the fields and upon doing that all of the other ones suddenly populated also. Then I took the parenthesis back out and it all continued to work with the original syntax. Very illogical.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top