473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dsum as ControlSource for text box on report not working

32
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 5746
Rabbit
12,516 Expert Mod 8TB
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
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 Expert Mod 8TB
It should be this:
"# <= [SavingsPeriodEndDate])"
Oct 19 '07 #4
ringer
32
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 Expert 512MB
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
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
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 Expert Mod 8TB
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
Yes! That did it. I've never seen that before. Thanks very much everybody, especially Rabbit!
Oct 19 '07 #10
ringer
32
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 Expert Mod 8TB
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
Thanks very much for your help!
Oct 30 '07 #13
Rabbit
12,516 Expert Mod 8TB
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.