Solved DSUM with multiple criteria.... (1 Viewer)

TajikBoy

Member
Local time
Today, 07:15
Joined
Mar 4, 2011
Messages
82
Hi Guys,

Trying to sum fields based on a ID from a form, and a text field, fixed - my version is below - what am I doing wrong?

=DSum([total],[qrybudget],"[ProjectName] = " & [me].[ID] & " And ctrBudgetType = 'Seed'")

ProjectName is a number field, and ctrBudgetType is a text.....

Thanks in advance,
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:15
Joined
May 7, 2009
Messages
19,233
=DSum("total","qrybudget","[ProjectName] = " & [me].[ID] & " And ctrBudgetType = 'Seed'")
 

TajikBoy

Member
Local time
Today, 07:15
Joined
Mar 4, 2011
Messages
82
=DSum("total","qrybudget","[ProjectName] = " & [me].[ID] & " And ctrBudgetType = 'Seed'")
Thanks but no sugar yet...Filed comes up as #Name?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:15
Joined
May 7, 2009
Messages
19,233
that's not a problem.
check each spelling if it does exists on qryBudget.
 

TajikBoy

Member
Local time
Today, 07:15
Joined
Mar 4, 2011
Messages
82
I can't see any misspelled field names, and query is working as it should be - Dsum should give total of 2 seeds, maybe one day ;)


query.png
output.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:15
Joined
May 7, 2009
Messages
19,233
maybe add square brackets.

=DSum("[total]","[qrybudget]","[ProjectName] = " & [me].[ID] & " And [ctrBudgetType] = 'Seed'")
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:15
Joined
May 7, 2009
Messages
19,233
maybe rename the Textbox to another name, ie, txtValue (by just prefixing with txt)
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:15
Joined
May 21, 2018
Messages
8,525
Instead of the Dsum can you just make an aggregate query
Group by project name, sum of total, where type = seed. Then link your query by project. If you want to only show seeds do an inner join, it you want all then do an outer join.
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:15
Joined
Sep 21, 2011
Messages
14,235
Put the criteria into a string variable and Debug.Print that to see what you produce.
 

TajikBoy

Member
Local time
Today, 07:15
Joined
Mar 4, 2011
Messages
82
Thanks guys, as I didn't get anywhere with multiple criteria, I built in the fixed element into the query and Dsum'ed with the projectName - now it works, not the ideal way but problem solved for now
 

Isaac

Lifelong Learner
Local time
Today, 07:15
Joined
Mar 14, 2017
Messages
8,774
Either you're typing/pasting it wrong, or your object names are misspelled, because the original response from Arnel is correct.
 

Users who are viewing this thread

Top Bottom