multi criteria DSum (1 Viewer)

Freddie b

New member
Local time
Today, 08:47
Joined
Sep 27, 2022
Messages
6
Can I write a DSum function in query, with two criteria?
that is, I want to collect quantities according to products from the beginning of the year to a certain date which is the date field in a form. I am trying to do a thing like this: =DSum("[qty]","salestbl","[PRODUCT H NAME] = “ field in form”[PRODUCT D NAME]") AND DATE =between “01.01.2021”, “A DATE IN FORM”.
 
Last edited:

Minty

AWF VIP
Local time
Today, 07:47
Joined
Jul 26, 2013
Messages
10,371
Look at the examples in my signature, and the similar threads at the bottom of the page.

=DSum("[qty]","salestbl","[PRODUCT H NAME] = '“ & Me.YourProductFormControlName & "' AND [DATE] = #“ & Format(Me.YourDateControl , "yyyy-mm-dd") & "#"

You need to concatenate the form values and use the correct string or date delimiters.

Also, rename your Field called [Date] to something else (SalesDates or InvDate) - Date is a reserved word and will give you a load of problems further down the line.
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:47
Joined
Sep 21, 2011
Messages
14,317
I tend to put the criteria into a string variable for domain functions if not a single simple criteria.
Then I can debug.print them to see if I have the syntax correct.
The when correct, I can use them in the function.
Plus, if you cannot see the error, you can copy and paste here or eslewhere, so someone can point out the error.?
 

Freddie b

New member
Local time
Today, 08:47
Joined
Sep 27, 2022
Messages
6
Look at the examples in my signature, and the similar threads at the bottom of the page.

=DSum("[qty]","salestbl","[PRODUCT H NAME] = '“ & Me.YourProductFormControlName & "' AND [DATE] = #“ & Format(Me.YourDateControl , "yyyy-mm-dd") & "#"

You need to concatenate the form values and use the correct string or date delimiters.

Also, rename your Field called [Date] to something else (SalesDates or InvDate) - Date is a reserved word and will give you a load of problems further down the line.
First of all thank you for your help,

I wrote this =Nz(DSum("[SASIA]","hyrje per log cmim mes","[PRODUCT H NAME]=" & [PRODUCT D NAME] & " and[DATA]<=#" & Format([ forms!FATURE SHITJE!DAT SH],"mm/dd/yyyy") & "#"),0) where [PRODUCT D NAME] is in sub form where i am writing and forms!FATURE SHITJE!DAT SH is in main form but it shows "#name?"
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:47
Joined
May 7, 2009
Messages
19,247
try:

=Nz(DSum("[SASIA]","hyrje per log cmim mes","[PRODUCT H NAME]='" & [Forms]![FATURE SHITJE]![subFormName].Form![PRODUCT D NAME] & "' and [DATA]<=#" & Format(Nz([Forms]![FATURE SHITJE]![DAT SH], 0), "\#mm\/dd\/yyyy\#")
 

Freddie b

New member
Local time
Today, 08:47
Joined
Sep 27, 2022
Messages
6
try:

=Nz(DSum("[SASIA]","hyrje per log cmim mes","[PRODUCT H NAME]='" & [Forms]![FATURE SHITJE]![subFormName].Form![PRODUCT D NAME] & "' and [DATA]<=#" & Format(Nz([Forms]![FATURE SHITJE]![DAT SH], 0), "\#mm\/dd\/yyyy\#")
Nothing again!
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:47
Joined
Sep 21, 2011
Messages
14,317
That is because you do not use the subform name, but the subformcontrol name.
Sometimes they are the same, but not always.
You are meant to change subformname to your actual subformcontrol name.
AGAIN!! if you put the criteria into a string variable, you can debug.print it, and if you get it correct, then use in the function.
You can also post the output here for review.
 

Cronk

Registered User.
Local time
Today, 16:47
Joined
Jul 4, 2013
Messages
2,772
Also the table name hyrje per log cmim mes should be in square brackets because it has spaces.

Experienced users would call the table HyrjePerLogCmiMmes
 

Users who are viewing this thread

Top Bottom