Solved DSum in datasource (1 Viewer)

hhag

Member
Local time
Today, 12:39
Joined
Mar 23, 2020
Messages
69
Hi,
I've entered the following in the rowsource for a textcontrol:


1588495485525.png


And I get '#Name?' as a result. And I can't figure out why? I'm using a Swedish version of Access, and I need to use semi-colon...
The intention is to summarize records in field 'TotalSum' in table 'tblTender' entered the previous month.

Does anyone have ny idea?
Thanks in advance!
Rgds
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:39
Joined
May 7, 2009
Messages
19,247
shouldn't you also enclosed in Quote (") the criteria?
Code:
=DSum("TotalSum"; "tblTender", "Year([TenderDate) * 12 + DatePart('m'; [TenderDate]) = " & _
Year(Date()) * 12 + DatePart("m"; Date()) -1)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:39
Joined
May 7, 2009
Messages
19,247
The intention is to summarize records in field 'TotalSum' in table 'tblTender' entered the previous month.
does it means from the beginning of the transaction up to Last Month?
Code:
=DSum("TotalSum"; "tblTender"; _
    "[TenderDate] <= #" & _
    DateSerial(Year(Date()); Month(Date()); 0) & "#")
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:39
Joined
Sep 21, 2011
Messages
14,319
Where does the Year * 12 come in to it?
 

jdraw

Super Moderator
Staff member
Local time
Today, 06:39
Joined
Jan 23, 2006
Messages
15,379
hhag,
Please describe your requirement in plain English so readers can understand WHAT you are trying to achieve. You are showing HOW you have tried to do something, but we need the WHAT clearly. There may be options for HOW it may be done.
 

hhag

Member
Local time
Today, 12:39
Joined
Mar 23, 2020
Messages
69
Hi,
Sorry. Pls, let me try again. And pls let me also expand my desire. My intention is always to try myself first, but when error messages don't disappear it gets a little frustrated :rolleyes:
Name of the table: tblTender (the domain)
Name of the field to summarize: TotalSum
Name of the field to set a criteria on: TenderDate

I've actually four different summaries that I would like to do and show the result in three different text boxes/controls. My intention is to write the DSum expressions in the rowsource to all three textboxes.

I want to summarize all records which have tender dates
1. =current month only.
2. = previous month only.
3. =current month, previous year.
4. = rolling 12 months, including current month.

And, thank you all for your help! I'm so thankful! 🙏
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:39
Joined
May 7, 2009
Messages
19,247
Code:
"current month"

=DSum("TotalSum"; "tblTender"; _ 
"Format([TenderDate]; 'mmyyyy') = '" & _
Format(Date(); "mmyyyy") & "'")

"previous month"
=DSum("TotalSum"; "tblTender"; _ 
"Format([TenderDate]; 'mmyyyy') = '" & _
Format(DateAdd("m";  -1; Date());  "mmyyyy") & "'")

"current month prev year"
=DSum("TotalSum"; "tblTender"; _ 
"Format([TenderDate]; 'mmyyyy') = '" & _
Format(DateAdd("yyyy";  -1; Date());  "mmyyyy") & "'")

"rolling 12 month"
=DSum("TotalSum"; "tblTender"; _ 
"Format([TenderDate]; 'yyyymm') >= '" & _
Format(DateAdd("m";  -12; Date());  "yyyymm") & "'")
 

onur_can

Active member
Local time
Today, 03:39
Joined
Oct 4, 2015
Messages
180
shouldn't you also enclosed in Quote (") the criteria?
Code:
=DSum("TotalSum"; "tblTender", "Year([TenderDate) * 12 + DatePart('m'; [TenderDate]) = " & _
Year(Date()) * 12 + DatePart("m"; Date()) -1)

"m" 'm'

which one is right ?

 

onur_can

Active member
Local time
Today, 03:39
Joined
Oct 4, 2015
Messages
180
I think you should transfer the criteria to the variables.

Code:
Dim a,b
a = Year([TenderDate) * 12 + DatePart("m"; [TenderDate])
b = Year(Date()) * 12 + DatePart("m"; Date()) -1)

txtTotal = DSum ("TotalSum";"tblTender";"a = '" & b & "'")
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:39
Joined
May 7, 2009
Messages
19,247
i used single quote on the first because it is inside the double qoute.

its better to actually run it. im not on pc right now, just typing on my cp.
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:39
Joined
Sep 21, 2011
Messages
14,319
I think you should transfer the criteria to the variables.

Code:
Dim a,b
a = Year([TenderDate) * 12 + DatePart("m"; [TenderDate])
b = Year(Date()) * 12 + DatePart("m"; Date()) -1)

txtTotal = DSum ("TotalSum";"tblTender";"a = '" & b & "'")
No real need now that arnelgp has supplied the correct syntax and code?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:39
Joined
May 7, 2009
Messages
19,247
I think you should transfer the criteria to the variables.

Code:
Dim a,b
a = Year([TenderDate) * 12 + DatePart("m"; [TenderDate])
b = Year(Date()) * 12 + DatePart("m"; Date()) -1)

txtTotal = DSum ("TotalSum";"tblTender";"a = '" & b & "'")
tenderdate is a fieldname. so it will complain that it cannot find it.
 

onur_can

Active member
Local time
Today, 03:39
Joined
Oct 4, 2015
Messages
180
Yes no need it.
It can be stored in a variable. But when you enter the Criterion, you must add the appropriate marks. You know that the data type is important when determining the criteria,
String,
The spelling of the Number and Date fields are separate from each other. Remember.
I gave the parameter as an example, it can be adjusted according to the returned result.
 
Last edited:

hhag

Member
Local time
Today, 12:39
Joined
Mar 23, 2020
Messages
69
After some changes I made it work. My intention was not to use the VBA editor, but then I decided to do so. And here I needed to swap ';' to ','.
I'm so grateful to all of you helping me out with all of my issues. Without your help, I fear I would have given up a long time ago.
Thank you for sharing your knowledge! 🙏 :)
And I know I'll soon ask for some more advice.
 

Users who are viewing this thread

Top Bottom