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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NEED HELP WITH DSUM()

Status
Not open for further replies.

calihiker

Technical User
Jun 13, 2003
96
US
I added additional criteria to my text box and I can't get it to work. Please Help!!!

Here's what I had before and it worked fine..

=Val(DSum("[QTY]","2000 to 2002 Gifts All Drops (Non Housefile Buyers)","[Year] = " & 2002))


Here's what I have now...

=Val(DSum("[QTY]","2000 to 2002 Gifts All Drops (Non Housefile Buyers)","[Year] = " & 2002 And [Sales/BK$]>=[txtMinimum_S/BK$].[Text]))

Any suggestions would be great, I'm not too familiar with sytax when adding more criteria for domain functions...
 
Hi calhiker,

I think it's a quotes problem again. The criteria passed to the Dsum Function needs to be a string and the only thing you want outside quotes is something which needs substituting in the building of that string. On your working original the 2002 should really have been inside the quotes but because it is numeric it made no difference. You should really have had ..

Code:
=Val(DSum("[QTY]","2000 to 2002 Gifts All Drops (Non Housefile Buyers)",
Code:
"[Year] = 2002"
Code:
))

The same rule applies on the new improved criteria. All that needs to be outside the quotes is the [txtMinimum_S/BK$].[Text] so you want to have ..

Code:
=Val(DSum("[QTY]","2000 to 2002 Gifts All Drops (Non Housefile Buyers)","[Year] = 2002 And [Sales/BK$]>=
Code:
" & [txtMinimum_S/BK$].[Text]
Code:
))

Enjoy,
Tony
 
I pasted the formula into the control source box and ran the form, but I got "#Error" in it? It didn't give me a syntax error, what would cause that?

Andre
 
Hi Andre,

#Error is a general error so it's often worth just playing around a little and seeing what has an effect. Is [txtMinimum_S/BK$] null? Or you could try changing [txtMinimum_S/BK$].[Text] to just [txtMinimum_S/BK$]. Hard to say for sure what might be causing it.

Enjoy,
Tony
 
Thanks, I took off the .text and it works fine now. :)
 
I have a similar problem now, how do you compare a field in a query to null? I need to count how many nulls are in a field in a table..
 
Hi Andre,

The arguments passed to the various domain functions are elements which are effectively combined to make an SQL statement. So, (and please don't cut and paste because I have left off some quotes and continuation marks for clarity) in the first example, your DSum ..

Code:
DSum("[QTY]"
     "2000 to 2002 Gifts All Drops (Non Housefile Buyers)"
     "[Year] = 2002 And [Sales/BK$]>= [txtMinimum_S/BK$])

.. is equivalent to ..

Code:
SELECT Sum([QTY])
FROM   [2000 to 2002 Gifts All Drops (Non Housefile Buyers)] 
WHERE  [Year] = 2002 And [Sales/BK$]>= [txtMinimum_S/BK$]

Now, your DCount. What you want in SQL is ..

Code:
SELECT Count(*)
FROM   YourTable
WHERE  YourColumn Is Null

.. so, as a domain function, you use

Code:
DCount("*",
       "YourTable",
       "YourColumn Is Null")

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top