473,503 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dsum as ControlSource for text box on report not working

32 New Member
Hi,
I have a text box on report where I need to have dsum return a total.
The records I need the total from are not in the table that is the report's recordsource, and to complicate things further, I need to use a variable that is derived from behind the report in the criteria for the dsum.

When I try to see print preview, this version of the statement errors before opening saying "Access cannot find the field 'SavingsPeriodEndDate' referred to in your expression":
Me.Text127.ControlSource = "=DSum('[CostPerPaycheck]','tblSavingsFunds','[FundsStatus] = 'Waiting' and #" & [nextpayday] & "# <= #" & [SavingsPeriodEndDate] & "#')"

[SavingsPeriodBeginDate]and [FundStatus] are fields in tblSavingsFunds.
nextpayday is a date variable set in the same section of code where this controlsource statement is (report_open).

Thank you
Oct 18 '07 #1
13 5765
Rabbit
12,516 Recognized Expert Moderator MVP
Hi,
I have a text box on report where I need to have dsum return a total.
The records I need the total from are not in the table that is the report's recordsource, and to complicate things further, I need to use a variable that is derived from behind the report in the criteria for the dsum.

When I try to see print preview, this version of the statement errors before opening saying "Access cannot find the field 'SavingsPeriodEndDate' referred to in your expression":
Me.Text127.ControlSource = "=DSum('[CostPerPaycheck]','tblSavingsFunds','[FundsStatus] = 'Waiting' and #" & [nextpayday] & "# <= #" & [SavingsPeriodEndDate] & "#')"

[SavingsPeriodBeginDate]and [FundStatus] are fields in tblSavingsFunds.
nextpayday is a date variable set in the same section of code where this controlsource statement is (report_open).

Thank you
And where is SavingsPeriodEndDate located?
Oct 18 '07 #2
ringer
32 New Member
Sorry, I got mixed up and typed the wrong field name. SavingsPeriodEndDate is also a field in the table tblSavingsFunds.
Oct 18 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
It should be this:
"# <= [SavingsPeriodEndDate])"
Oct 19 '07 #4
ringer
32 New Member
I tried your suggestion
and #" & [nextpayday] & "# <= [SavingsPeriodEndDate])"
and
and #" & [nextpayday] & "# <= [SavingsPeriodEndDate]')" -notice the single quote between ] and )

Both give error 2434, invalid syntax.

Then I tried
and #" & [nextpayday] & "# <= [SavingsPeriodEndDate])" and removing the single quote before [FundStatus] but that prompted for a value for FundStatus when I tried to print preview.
Oct 19 '07 #5
patjones
931 Recognized Expert Contributor
Maybe you could try removing the quotes from around the date fields:

' [FundsStatus] = 'Waiting' And #[nextpayday]# <= #[SavingsPeriodEndDate]# '

But it might be more complicated than that. I find that Access doesn't like date comparisons such as [Date1] < [Date2] when one or both of the date values is null, or an empty string. If you have null dates in your table, it might be complaining about that.
Oct 19 '07 #6
ringer
32 New Member
Maybe you could try removing the quotes from around the date fields
Thanks for the suggestion Zepphead, but when I tried it errored saying "invalid syntax".

Then I tried removing the [ ] from around the date variable nextpayday like this:

and #" & nextpayday & "# <= #" & [SavingsPeriodEndDate] & "#')"
and this
and #" & nextpayday & "# <= #" & CDate([SavingsPeriodEndDate]) & "#')"

but when attempting print preview, both gave the error "Access can't find the field 'SavingsPeriodEndDate' referred to in your expression".

Then I tried:
and #" & nextpayday & "# <= #" & CDate([tblSavingsFunds].[SavingsPeriodEndDate]) & "#')"
and also
and #" & nextpayday & "# <= #" & [tblSavingsFunds].[SavingsPeriodEndDate] & "#')"

but when trying to print preview, both gave the error:
"Access can't find the field '|' referred to in your expression"
Oct 19 '07 #7
ringer
32 New Member
But it might be more complicated than that. I find that Access doesn't like date comparisons such as [Date1] < [Date2] when one or both of the date values is null, or an empty string. If you have null dates in your table, it might be complaining about that.
I've seen that before too and have had to build logic in to intercept that situation when it comes up, but I don't think that's happening here.
I found that for some reason this works:
Me.Text127.ControlSource = and t=DSum('[CostPerPaycheck]','tblSavingsFunds','[SavingsPeriodEndDate] >= #" & nextpayday & "#')"

but it stops working when I add this criteria back into the string:
and [FundStatus] = 'Waiting'

Like this it errors saying invalid syntax when attempting a print preview:
Me.Text127.ControlSource = "=DSum('[CostPerPaycheck]','tblSavingsFunds','[SavingsPeriodEndDate] >= #" & nextpayday & "# and [FundsStatus] = 'Waiting'')"

Here I removed the single quotes from the whole criteria statement, and now it returns a total of all CostPerPaycheck fields in the table if the first record has [FundStatus] = 'Waiting', but returns nothing if the first record doesn't:
Me.Text127.ControlSource = "=DSum('[CostPerPaycheck]','tblSavingsFunds',[SavingsPeriodEndDate] >= #" & nextpayday & "# and [FundStatus] = 'Waiting')"
Oct 19 '07 #8
Rabbit
12,516 Recognized Expert Moderator MVP
Ok, I think I see now. Use this:
Expand|Select|Wrap|Line Numbers
  1. Me.Text127.ControlSource = "=DSum('[CostPerPaycheck]','tblSavingsFunds','[SavingsPeriodEndDate] >= #" & nextpayday & "# and [FundStatus] = ""Waiting""')"
  2.  
Oct 19 '07 #9
ringer
32 New Member
Yes! That did it. I've never seen that before. Thanks very much everybody, especially Rabbit!
Oct 19 '07 #10
ringer
32 New Member
One other quick question about this. How can I make this statement return 0.00 when nothing matches the criteria? Right now the text box is blank when nothing matches the criteria.
Oct 19 '07 #11
Rabbit
12,516 Recognized Expert Moderator MVP
Surround that with the Nz function. Nz returns an alternate value if the value you give it is Null.

Nz(DSum(), 0.00)
Oct 19 '07 #12
ringer
32 New Member
Thanks very much for your help!
Oct 30 '07 #13
Rabbit
12,516 Recognized Expert Moderator MVP
Not a problem, good luck.
Oct 30 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4787
by: Dalan | last post by:
I have tried both methods of using DSum and creating a Function to address summing some number columns, but to no avail. Since this has been a popular topic over the years, I'm sure I'll receive...
1
3946
by: Dalan | last post by:
This seems a bit odd, but I have not been able to persuade Access 97 to format several DSum total columns in Currency - Standard format. It appears to be defaulting to a general number format...
2
11560
by: Dalan | last post by:
I seemed to be having problems with structuring the use of NZ with a DSum expression. Having tried numerous variations of the expression without success, I'm asking for assistance. First some...
3
3745
by: Mark Reed | last post by:
All, I have never used this function before and am not sure it what I need. Just to clarify, I have a report based on a query which has amoungst other field, wk, parea & packs_req. What I am...
4
2643
by: John Baker | last post by:
Hi: At the bottom of a report, I wish to sum all the amounts that appear in a field called Discount$ that appears on the report. I am not doing this summing in the query that supports the report...
6
6264
by: ckpoll2 | last post by:
Hi, I have made a report that has a query as its record source. I put a text box in there that I want to run a dsum function off of a different query. The criteria that I need to use is that it...
3
2977
by: technocraze | last post by:
Hi community experts, I am having an isue with Dsum function that is used to count the total number for a particular field (intake) at the textbox afterupdate event with condition/ criteria...
1
3842
by: danielgoss | last post by:
Hi I have a report that has loads of textboxes that calculate things based on the value on another textbox in the report. I have put a hidden textbox on my report that gets its value from an...
9
5408
by: BlackJack17 | last post by:
Alright you all have been so helpful with everything else that I thought I'd run one more issue by you. I have put together a report that is driven by a query. This query (Unique Records) returns...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7348
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7006
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.