Dsum Syntax Help (1 Viewer)

Drand

Registered User.
Local time
Today, 15:06
Joined
Jun 8, 2019
Messages
179
Hi all

I have a Dsum calculation as follows:

JanCofAct = Nz(DSum("[CostIncGST]", "QryStockOutThisYearForBudget", "[Grp] = 'Coffee' and MonthName = 'Jan'"), 0)

I need to add a year criteria where MyYear (as an integer) is derived from a user input box when the form loads.

So what I am trying to achieve is

JanCofAct = Nz(DSum("[CostIncGST]", "QryStockOutThisYearForBudget", "[Grp] = 'Coffee' and MonthName = 'Jan'"), 0) and MyYear = the inputbox result
but I do not know the correct syntax for this.

Would appreciate your assistance

Many thanks
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:06
Joined
Oct 29, 2018
Messages
21,473
Hi. Just a guess, but maybe you could try something like:
Code:
JanCofAct = DSum("[CostIncGST]", "QryStockOutThisYearForBudget", "[Grp] = 'Coffee' And MonthName = 'Jan' And MyYear=InputBox(Enter Year)")
Hope that helps...
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:06
Joined
Feb 19, 2002
Messages
43,275
JanCofAct =
Really? You want to do a dSum() for every expense for every month by year? There are much better ways. Why not tell us what your objective is instead of asking us how to fix your solution which may not even be what you should be doing?

For starters, a cross tab that took Year as an argument would give you ALL expenses as a list with 12 months across the top. Tell us what you want and we'll help you get there:)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:06
Joined
May 7, 2009
Messages
19,243
Dim lngYear As Long
lngYear = Val(InputBox("Enter Year", , Year(Date)))
JanCofAct = DSum("[CostIncGST]", "QryStockOutThisYearForBudget", "[Grp] = 'Coffee' And MonthName = 'Jan' And [Year] = " & lngYear)
 

Users who are viewing this thread

Top Bottom