DSUM Multiple Criteria issue (1 Viewer)

JHarmon

New member
Local time
Yesterday, 21:44
Joined
Aug 3, 2015
Messages
7
Hello all,
I am new here and need some help with a DSUM issue. I don't use this function often and can't seem to make it work when using two sets of criteria. Here is what it looks like. The output is all the same value. It works until I add the AND section. Any help is greatly appreciated.

Expr1: DSum("[OpenPO]![Open Tons]","OPenPO","[Delivery Date]=#" & [Start Date] & "#" And "[Material] ='" & [Component] & "'")
 

JHarmon

New member
Local time
Yesterday, 21:44
Joined
Aug 3, 2015
Messages
7
It returns the entire SUM of Open Tons
 

Minty

AWF VIP
Local time
Today, 05:44
Joined
Jul 26, 2013
Messages
10,371
You have your quotes all muddled up

Expr1: DSum("[OpenPO]![Open Tons]","OPenPO","[Delivery Date]=#" & [Start Date] & "#" And "[Material] ='" & [Component] & "'")

Should be
Code:
 Expr1: DSum("[OpenPO]![Open Tons]","OPenPO","[Delivery Date]=#" & [Start Date] & "# And [Material] ='" & [Component] & "'")
 

JHarmon

New member
Local time
Yesterday, 21:44
Joined
Aug 3, 2015
Messages
7
Bob,
I figured it out. I removed the " after the second # and before [Material] and it worked. Thank you for checking. I greatly appreciate it.
 

JHarmon

New member
Local time
Yesterday, 21:44
Joined
Aug 3, 2015
Messages
7
Thank you so much. I have spent hours trying to get this to work
 

JHarmon

New member
Local time
Yesterday, 21:44
Joined
Aug 3, 2015
Messages
7
Minty,
Sorry to bother you again. What would it look like to make this work BETWEEN two dates. Ex: BETWEEN [Start Date] AND [End Date] AND [Material]...
 

Minty

AWF VIP
Local time
Today, 05:44
Joined
Jul 26, 2013
Messages
10,371
Are your dates just dates or are they datetimes ?
 

Minty

AWF VIP
Local time
Today, 05:44
Joined
Jul 26, 2013
Messages
10,371
If they are straight dates it's allegedly simple;
Code:
DSum("[OpenPO]![Open Tons]","OPenPO","[Delivery Date] Between #" & [Start Date] & "# And  #" & [EndDate] & # AND [Material] ='" & [Component] & "'")
 

JHarmon

New member
Local time
Yesterday, 21:44
Joined
Aug 3, 2015
Messages
7
I am getting an Invalid Date Value error from the following code

# AND [Material] ='" & [Component] & "'")
 

Minty

AWF VIP
Local time
Today, 05:44
Joined
Jul 26, 2013
Messages
10,371
I am getting an Invalid Date Value error from the following code

# AND [Material] ='" & [Component] & "'")

I've missed a quote apologies !

However as a hint to finding problems with complicated criteria can I suggest you build the criteria as a string before the dlookup / dsum e.g.

Code:
dim strCriteria as string
strCriteria = "[Delivery Date] Between #" & [Start Date] & "# And  #" & [EndDate] & [COLOR="Red"][B]"[/B][/COLOR]# AND [Material] ='" & [Component] & "'")
msgbox strCriteria  'or debug.print strCriteria
DSum("[OpenPO]![Open Tons]","OPenPO", sCriteria)
This is handy as you can see what's in your criteria as it runs.
 

Users who are viewing this thread

Top Bottom