473,386 Members | 1,958 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,386 software developers and data experts.

Running Totals Query Access97

I'm trying to create a running totals query in access 97. I have
followed the directions on how to do it from Microsofts website
article id 138911. I took their code they had and replaced it with my
fields. When I try to run it I get #errors in my RunTot column. I'm
kinda new to this. Not sure if maybe I mistyped something wrong or is
there a better way to do this? I have pasted the code. Any help would
be greatly appreciated. Thanks.

SELECT [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]) AS AYear, DatePart("m",[Inbound
Date]) AS AMonth, DSum("Contract Price","Quotes &
Orders","Datepart('m',[Inbound Date])<=" & [Amonth] & "And
Datepart('yyyy',[Inbound date])<=" & [ayear] & "") AS RunTot,
Format([Inbound Date],"mmm") AS FDate
FROM [Quotes & Orders]
WHERE (((DatePart("yyyy",[Inbound Date]))=[Enter Year]))
GROUP BY [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]), DatePart("m",[Inbound Date]),
Format([Inbound Date],"mmm")
HAVING ((([Quotes & Orders].[Inbound Date]) Is Not Null) AND (([Quotes
& Orders].[Sales Rep])=[Enter Salesman]))
ORDER BY [Quotes & Orders].[Inbound Date], DatePart("yyyy",[Inbound
Date]), DatePart("m",[Inbound Date]), Format([Inbound Date],"mmm");

Jun 20 '07 #1
9 3992
On Wed, 20 Jun 2007 14:24:19 -0000, JJM0926 <jj*****@gmail.comwrote:

You're starting the column expression for RunTot with a double-quote,
whereas the similar AYear does not.

-Tom.

>I'm trying to create a running totals query in access 97. I have
followed the directions on how to do it from Microsofts website
article id 138911. I took their code they had and replaced it with my
fields. When I try to run it I get #errors in my RunTot column. I'm
kinda new to this. Not sure if maybe I mistyped something wrong or is
there a better way to do this? I have pasted the code. Any help would
be greatly appreciated. Thanks.

SELECT [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]) AS AYear, DatePart("m",[Inbound
Date]) AS AMonth, DSum("Contract Price","Quotes &
Orders","Datepart('m',[Inbound Date])<=" & [Amonth] & "And
Datepart('yyyy',[Inbound date])<=" & [ayear] & "") AS RunTot,
Format([Inbound Date],"mmm") AS FDate
FROM [Quotes & Orders]
WHERE (((DatePart("yyyy",[Inbound Date]))=[Enter Year]))
GROUP BY [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]), DatePart("m",[Inbound Date]),
Format([Inbound Date],"mmm")
HAVING ((([Quotes & Orders].[Inbound Date]) Is Not Null) AND (([Quotes
& Orders].[Sales Rep])=[Enter Salesman]))
ORDER BY [Quotes & Orders].[Inbound Date], DatePart("yyyy",[Inbound
Date]), DatePart("m",[Inbound Date]), Format([Inbound Date],"mmm");
Jun 20 '07 #2
On Jun 20, 9:30 am, Tom van Stiphout <no.spam.tom7...@cox.netwrote:
On Wed, 20 Jun 2007 14:24:19 -0000, JJM0926 <jjm0...@gmail.comwrote:

You're starting the column expression for RunTot with a double-quote,
whereas the similar AYear does not.

-Tom.
I'm trying to create a running totals query in access 97. I have
followed the directions on how to do it from Microsofts website
article id 138911. I took their code they had and replaced it with my
fields. When I try to run it I get #errors in my RunTot column. I'm
kinda new to this. Not sure if maybe I mistyped something wrong or is
there a better way to do this? I have pasted the code. Any help would
be greatly appreciated. Thanks.
SELECT [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]) AS AYear, DatePart("m",[Inbound
Date]) AS AMonth, DSum("Contract Price","Quotes &
Orders","Datepart('m',[Inbound Date])<=" & [Amonth] & "And
Datepart('yyyy',[Inbound date])<=" & [ayear] & "") AS RunTot,
Format([Inbound Date],"mmm") AS FDate
FROM [Quotes & Orders]
WHERE (((DatePart("yyyy",[Inbound Date]))=[Enter Year]))
GROUP BY [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]), DatePart("m",[Inbound Date]),
Format([Inbound Date],"mmm")
HAVING ((([Quotes & Orders].[Inbound Date]) Is Not Null) AND (([Quotes
& Orders].[Sales Rep])=[Enter Salesman]))
ORDER BY [Quotes & Orders].[Inbound Date], DatePart("yyyy",[Inbound
Date]), DatePart("m",[Inbound Date]), Format([Inbound Date],"mmm");- Hide quoted text -

- Show quoted text -
When I remove the double quotes I get a syntax error and it will not
even allow me to run the query. Thanks.
Jun 20 '07 #3
JJM0926 wrote:
I'm trying to create a running totals query in access 97. I have
followed the directions on how to do it from Microsofts website
article id 138911. I took their code they had and replaced it with my
fields. When I try to run it I get #errors in my RunTot column. I'm
kinda new to this. Not sure if maybe I mistyped something wrong or is
there a better way to do this? I have pasted the code. Any help would
be greatly appreciated. Thanks.

SELECT [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]) AS AYear, DatePart("m",[Inbound
Date]) AS AMonth, DSum("Contract Price","Quotes &
Orders","Datepart('m',[Inbound Date])<=" & [Amonth] & "And
Datepart('yyyy',[Inbound date])<=" & [ayear] & "") AS RunTot,
Format([Inbound Date],"mmm") AS FDate
FROM [Quotes & Orders]
WHERE (((DatePart("yyyy",[Inbound Date]))=[Enter Year]))
GROUP BY [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]), DatePart("m",[Inbound Date]),
Format([Inbound Date],"mmm")
HAVING ((([Quotes & Orders].[Inbound Date]) Is Not Null) AND (([Quotes
& Orders].[Sales Rep])=[Enter Salesman]))
ORDER BY [Quotes & Orders].[Inbound Date], DatePart("yyyy",[Inbound
Date]), DatePart("m",[Inbound Date]), Format([Inbound Date],"mmm");
AYear and Amonth haven't been defined when using them in dsum. BTW, why
are you using DatePart when Year(Datefield) and Month(Datefield) is more
readable and does the same thing?

The more I look at your query the bigger the mess it becomes. And your
orderby line is goofy.

I'd suggest you create a query that creates AYear and Amonth columns and
asks for the salesperson and year and does any and all filtering (Ex:
Query1). Then create another query (Query2) and make the first query
the data table you total and group on.
Jun 20 '07 #4
On Jun 20, 10:02 am, salad <o...@vinegar.comwrote:
JJM0926 wrote:
I'm trying to create a running totals query in access 97. I have
followed the directions on how to do it from Microsofts website
article id 138911. I took their code they had and replaced it with my
fields. When I try to run it I get #errors in my RunTot column. I'm
kinda new to this. Not sure if maybe I mistyped something wrong or is
there a better way to do this? I have pasted the code. Any help would
be greatly appreciated. Thanks.
SELECT [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]) AS AYear, DatePart("m",[Inbound
Date]) AS AMonth, DSum("Contract Price","Quotes &
Orders","Datepart('m',[Inbound Date])<=" & [Amonth] & "And
Datepart('yyyy',[Inbound date])<=" & [ayear] & "") AS RunTot,
Format([Inbound Date],"mmm") AS FDate
FROM [Quotes & Orders]
WHERE (((DatePart("yyyy",[Inbound Date]))=[Enter Year]))
GROUP BY [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]), DatePart("m",[Inbound Date]),
Format([Inbound Date],"mmm")
HAVING ((([Quotes & Orders].[Inbound Date]) Is Not Null) AND (([Quotes
& Orders].[Sales Rep])=[Enter Salesman]))
ORDER BY [Quotes & Orders].[Inbound Date], DatePart("yyyy",[Inbound
Date]), DatePart("m",[Inbound Date]), Format([Inbound Date],"mmm");

AYear and Amonth haven't been defined when using them in dsum. BTW, why
are you using DatePart when Year(Datefield) and Month(Datefield) is more
readable and does the same thing?

The more I look at your query the bigger the mess it becomes. And your
orderby line is goofy.

I'd suggest you create a query that creates AYear and Amonth columns and
asks for the salesperson and year and does any and all filtering (Ex:
Query1). Then create another query (Query2) and make the first query
the data table you total and group on.- Hide quoted text -

- Show quoted text -
This is the method that I got from Microsoft's website. I'm just
trying to figure out why I am getting the #error in my RunTot column.
As I mentioned I'm kinda new to access and sql statements. All I did
was take Microsoft's code and change them to match my column
headings. Thanks.

Jun 20 '07 #5
JJM0926 wrote:
On Jun 20, 10:02 am, salad <o...@vinegar.comwrote:
>>JJM0926 wrote:
>>>I'm trying to create a running totals query in access 97. I have
followed the directions on how to do it from Microsofts website
article id 138911. I took their code they had and replaced it with my
fields. When I try to run it I get #errors in my RunTot column. I'm
kinda new to this. Not sure if maybe I mistyped something wrong or is
there a better way to do this? I have pasted the code. Any help would
be greatly appreciated. Thanks.
>>>SELECT [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]) AS AYear, DatePart("m",[Inbound
Date]) AS AMonth, DSum("Contract Price","Quotes &
Orders","Datepart('m',[Inbound Date])<=" & [Amonth] & "And
Datepart('yyyy',[Inbound date])<=" & [ayear] & "") AS RunTot,
Format([Inbound Date],"mmm") AS FDate
FROM [Quotes & Orders]
WHERE (((DatePart("yyyy",[Inbound Date]))=[Enter Year]))
GROUP BY [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]), DatePart("m",[Inbound Date]),
Format([Inbound Date],"mmm")
HAVING ((([Quotes & Orders].[Inbound Date]) Is Not Null) AND (([Quotes
& Orders].[Sales Rep])=[Enter Salesman]))
ORDER BY [Quotes & Orders].[Inbound Date], DatePart("yyyy",[Inbound
Date]), DatePart("m",[Inbound Date]), Format([Inbound Date],"mmm");

AYear and Amonth haven't been defined when using them in dsum. BTW, why
are you using DatePart when Year(Datefield) and Month(Datefield) is more
readable and does the same thing?

The more I look at your query the bigger the mess it becomes. And your
orderby line is goofy.

I'd suggest you create a query that creates AYear and Amonth columns and
asks for the salesperson and year and does any and all filtering (Ex:
Query1). Then create another query (Query2) and make the first query
the data table you total and group on.- Hide quoted text -

- Show quoted text -


This is the method that I got from Microsoft's website. I'm just
trying to figure out why I am getting the #error in my RunTot column.
As I mentioned I'm kinda new to access and sql statements. All I did
was take Microsoft's code and change them to match my column
headings. Thanks.
I assume there can be multiple records for the inbound date for a sales rep.

Query1. This select all of the records and rolls up the totals for the
rep you filter on by the inbound date.
SELECT [Inbound Date], [Sales Rep], Year([Inbound Date]) &
Month([Inbound Date]) As YyyyMm, Sum(Contract Price) As CPSum
FROM [Quotes & Orders]
WHERE Year([Inbound Date])=[Enter Year] And [Sales Rep] = [Enter Salesman]
Group By [Inbound Date], [Sales Rep], Year([Inbound Date]) &
Month([Inbound Date])
Query2. This creates the running sum
Select [Inbound Date], [Sales Rep], YyyyMm, CPSum,
DSum("CPSum","Query1","YyyyMm < " & [YyyyMm]) As RunTot
From Query1
Order By [Inbound Date]

This is just a suggestion. Lose the spaces in your field names.
Instead of
Inbound Date or Sales Rep
use
InboundDate or SalesRep

If you work in Access for a while you'll discover you add a lot of work
and will expend a lot of energy by creating field names with spaces.
Jun 20 '07 #6
On Jun 20, 5:11 pm, salad <o...@vinegar.comwrote:
JJM0926 wrote:
On Jun 20, 10:02 am, salad <o...@vinegar.comwrote:
>JJM0926 wrote:
>>I'm trying to create a running totals query in access 97. I have
followed the directions on how to do it from Microsofts website
article id 138911. I took their code they had and replaced it with my
fields. When I try to run it I get #errors in my RunTot column. I'm
kinda new to this. Not sure if maybe I mistyped something wrong or is
there a better way to do this? I have pasted the code. Any help would
be greatly appreciated. Thanks.
>>SELECT [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]) AS AYear, DatePart("m",[Inbound
Date]) AS AMonth, DSum("Contract Price","Quotes &
Orders","Datepart('m',[Inbound Date])<=" & [Amonth] & "And
Datepart('yyyy',[Inbound date])<=" & [ayear] & "") AS RunTot,
Format([Inbound Date],"mmm") AS FDate
FROM [Quotes & Orders]
WHERE (((DatePart("yyyy",[Inbound Date]))=[Enter Year]))
GROUP BY [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]), DatePart("m",[Inbound Date]),
Format([Inbound Date],"mmm")
HAVING ((([Quotes & Orders].[Inbound Date]) Is Not Null) AND (([Quotes
& Orders].[Sales Rep])=[Enter Salesman]))
ORDER BY [Quotes & Orders].[Inbound Date], DatePart("yyyy",[Inbound
Date]), DatePart("m",[Inbound Date]), Format([Inbound Date],"mmm");
>AYear and Amonth haven't been defined when using them in dsum. BTW, why
are you using DatePart when Year(Datefield) and Month(Datefield) is more
readable and does the same thing?
>The more I look at your query the bigger the mess it becomes. And your
orderby line is goofy.
>I'd suggest you create a query that creates AYear and Amonth columns and
asks for the salesperson and year and does any and all filtering (Ex:
Query1). Then create another query (Query2) and make the first query
the data table you total and group on.- Hide quoted text -
>- Show quoted text -
This is the method that I got from Microsoft's website. I'm just
trying to figure out why I am getting the #error in my RunTot column.
As I mentioned I'm kinda new to access and sql statements. All I did
was take Microsoft's code and change them to match my column
headings. Thanks.

I assume there can be multiple records for the inbound date for a sales rep.

Query1. This select all of the records and rolls up the totals for the
rep you filter on by the inbound date.
SELECT [Inbound Date], [Sales Rep], Year([Inbound Date]) &
Month([Inbound Date]) As YyyyMm, Sum(Contract Price) As CPSum
FROM [Quotes & Orders]
WHERE Year([Inbound Date])=[Enter Year] And [Sales Rep] = [Enter Salesman]
Group By [Inbound Date], [Sales Rep], Year([Inbound Date]) &
Month([Inbound Date])

Query2. This creates the running sum
Select [Inbound Date], [Sales Rep], YyyyMm, CPSum,
DSum("CPSum","Query1","YyyyMm < " & [YyyyMm]) As RunTot
From Query1
Order By [Inbound Date]

This is just a suggestion. Lose the spaces in your field names.
Instead of
Inbound Date or Sales Rep
use
InboundDate or SalesRep

If you work in Access for a while you'll discover you add a lot of work
and will expend a lot of energy by creating field names with spaces.- Hide quoted text -

- Show quoted text -
Thanks Salad. Your first query kinda worked, except it thru in the
year with the month in the same column. Is there a way to separate
the year in one column and the month in another? Your second query
didn't quite work so well. When I ran it I still got #error on
RunTot. This the error message that it gave me. The expression you
entered as a query parameter produce this error: "The object doesn't
contain the Automation object 'Enter Year." Thanks again for you help.

Jun 21 '07 #7
JJM0926 wrote:
On Jun 20, 5:11 pm, salad <o...@vinegar.comwrote:
>>JJM0926 wrote:
>>>On Jun 20, 10:02 am, salad <o...@vinegar.comwrote:
>>>>JJM0926 wrote:
>>>>>I'm trying to create a running totals query in access 97. I have
>followed the directions on how to do it from Microsofts website
>article id 138911. I took their code they had and replaced it with my
>fields. When I try to run it I get #errors in my RunTot column. I'm
>kinda new to this. Not sure if maybe I mistyped something wrong or is
>there a better way to do this? I have pasted the code. Any help would
>be greatly appreciated. Thanks.
>>>>>SELECT [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
>Rep], DatePart("yyyy",[Inbound Date]) AS AYear, DatePart("m",[Inbound
>Date]) AS AMonth, DSum("Contract Price","Quotes &
>Orders","Datepart('m',[Inbound Date])<=" & [Amonth] & "And
>Datepart('yyyy',[Inbound date])<=" & [ayear] & "") AS RunTot,
>Format([Inbound Date],"mmm") AS FDate

>FROM [Quotes & Orders]

>WHERE (((DatePart("yyyy",[Inbound Date]))=[Enter Year]))
>GROUP BY [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
>Rep], DatePart("yyyy",[Inbound Date]), DatePart("m",[Inbound Date]),
>Format([Inbound Date],"mmm")
>HAVING ((([Quotes & Orders].[Inbound Date]) Is Not Null) AND (([Quotes
>& Orders].[Sales Rep])=[Enter Salesman]))
>ORDER BY [Quotes & Orders].[Inbound Date], DatePart("yyyy",[Inbound
>Date]), DatePart("m",[Inbound Date]), Format([Inbound Date],"mmm");
>>>>AYear and Amonth haven't been defined when using them in dsum. BTW, why
are you using DatePart when Year(Datefield) and Month(Datefield) is more
readable and does the same thing?
>>>>The more I look at your query the bigger the mess it becomes. And your
orderby line is goofy.
>>>>I'd suggest you create a query that creates AYear and Amonth columns and
asks for the salesperson and year and does any and all filtering (Ex:
Query1). Then create another query (Query2) and make the first query
the data table you total and group on.- Hide quoted text -
>>>>- Show quoted text -
>>>This is the method that I got from Microsoft's website. I'm just
trying to figure out why I am getting the #error in my RunTot column.
As I mentioned I'm kinda new to access and sql statements. All I did
was take Microsoft's code and change them to match my column
headings. Thanks.

I assume there can be multiple records for the inbound date for a sales rep.

Query1. This select all of the records and rolls up the totals for the
rep you filter on by the inbound date.
SELECT [Inbound Date], [Sales Rep], Year([Inbound Date]) &
Month([Inbound Date]) As YyyyMm, Sum(Contract Price) As CPSum
FROM [Quotes & Orders]
WHERE Year([Inbound Date])=[Enter Year] And [Sales Rep] = [Enter Salesman]
Group By [Inbound Date], [Sales Rep], Year([Inbound Date]) &
Month([Inbound Date])

Query2. This creates the running sum
Select [Inbound Date], [Sales Rep], YyyyMm, CPSum,
DSum("CPSum","Query1","YyyyMm < " & [YyyyMm]) As RunTot
From Query1
Order By [Inbound Date]

This is just a suggestion. Lose the spaces in your field names.
Instead of
Inbound Date or Sales Rep
use
InboundDate or SalesRep

If you work in Access for a while you'll discover you add a lot of work
and will expend a lot of energy by creating field names with spaces.- Hide quoted text -

- Show quoted text -


Thanks Salad. Your first query kinda worked, except it thru in the
year with the month in the same column. Is there a way to separate
the year in one column and the month in another? Your second query
didn't quite work so well. When I ran it I still got #error on
RunTot. This the error message that it gave me. The expression you
entered as a query parameter produce this error: "The object doesn't
contain the Automation object 'Enter Year." Thanks again for you help.
I create a table called Test. I then created 2 queries. The field
names are slightly different but you should be able to figure them out.

I actually created 2 running tot columns. First col is a running date
between dates. The other is a running sum between months. The reason
this was done is because there is a group on Idate, thus making a totals
record for each date.

QueryTest1
SELECT Test.IDate, Test.Rep, Sum(Test.Price) AS SumPrice, Year([Idate])
AS YearDate, Month([Idate]) AS MonDate
FROM Test
GROUP BY Test.IDate, Test.Rep, Year([Idate]), Month([Idate]);
QueryTest2
SELECT QueryTest1.IDate, QueryTest1.Rep, QueryTest1.YearDate,
QueryTest1.MonDate, QueryTest1.SumPrice,
NZ(DSum("SumPrice","QueryTest1","Idate < #" & [Idate] & "#"),0) AS
RunTotByDate, NZ(DSum("SumPrice","QueryTest1","Year([Idate]) &
Month([Idate]) < " & Year([Idate]) & Month([Idate])),0) AS RunTotByMonth
FROM QueryTest1
WHERE (((QueryTest1.Rep)=[Enter Rep]) AND ((QueryTest1.YearDate)=[Enter
Year]));
Jun 21 '07 #8
On Jun 21, 1:07 pm, salad <o...@vinegar.comwrote:
JJM0926 wrote:
On Jun 20, 5:11 pm, salad <o...@vinegar.comwrote:
>JJM0926 wrote:
>>On Jun 20, 10:02 am, salad <o...@vinegar.comwrote:
>>>JJM0926 wrote:
>>>>I'm trying to create a running totals query in access 97. I have
followed the directions on how to do it from Microsofts website
article id 138911. I took their code they had and replaced it with my
fields. When I try to run it I get #errors in my RunTot column. I'm
kinda new to this. Not sure if maybe I mistyped something wrong or is
there a better way to do this? I have pasted the code. Any help would
be greatly appreciated. Thanks.
>>>>SELECT [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]) AS AYear, DatePart("m",[Inbound
Date]) AS AMonth, DSum("Contract Price","Quotes &
Orders","Datepart('m',[Inbound Date])<=" & [Amonth] & "And
Datepart('yyyy',[Inbound date])<=" & [ayear] & "") AS RunTot,
Format([Inbound Date],"mmm") AS FDate
>>>>FROM [Quotes & Orders]
>>>>WHERE (((DatePart("yyyy",[Inbound Date]))=[Enter Year]))
GROUP BY [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
Rep], DatePart("yyyy",[Inbound Date]), DatePart("m",[Inbound Date]),
Format([Inbound Date],"mmm")
HAVING ((([Quotes & Orders].[Inbound Date]) Is Not Null) AND (([Quotes
& Orders].[Sales Rep])=[Enter Salesman]))
ORDER BY [Quotes & Orders].[Inbound Date], DatePart("yyyy",[Inbound
Date]), DatePart("m",[Inbound Date]), Format([Inbound Date],"mmm");
>>>AYear and Amonth haven't been defined when using them in dsum. BTW, why
are you using DatePart when Year(Datefield) and Month(Datefield) is more
readable and does the same thing?
>>>The more I look at your query the bigger the mess it becomes. And your
orderby line is goofy.
>>>I'd suggest you create a query that creates AYear and Amonth columns and
asks for the salesperson and year and does any and all filtering (Ex:
Query1). Then create another query (Query2) and make the first query
the data table you total and group on.- Hide quoted text -
>>>- Show quoted text -
>>This is the method that I got from Microsoft's website. I'm just
trying to figure out why I am getting the #error in my RunTot column.
As I mentioned I'm kinda new to access and sql statements. All I did
was take Microsoft's code and change them to match my column
headings. Thanks.
>I assume there can be multiple records for the inbound date for a sales rep.
>Query1. This select all of the records and rolls up the totals for the
rep you filter on by the inbound date.
SELECT [Inbound Date], [Sales Rep], Year([Inbound Date]) &
Month([Inbound Date]) As YyyyMm, Sum(Contract Price) As CPSum
FROM [Quotes & Orders]
WHERE Year([Inbound Date])=[Enter Year] And [Sales Rep] = [Enter Salesman]
Group By [Inbound Date], [Sales Rep], Year([Inbound Date]) &
Month([Inbound Date])
>Query2. This creates the running sum
Select [Inbound Date], [Sales Rep], YyyyMm, CPSum,
DSum("CPSum","Query1","YyyyMm < " & [YyyyMm]) As RunTot
From Query1
Order By [Inbound Date]
>This is just a suggestion. Lose the spaces in your field names.
Instead of
Inbound Date or Sales Rep
use
InboundDate or SalesRep
>If you work in Access for a while you'll discover you add a lot of work
and will expend a lot of energy by creating field names with spaces.- Hide quoted text -
>- Show quoted text -
Thanks Salad. Your first query kinda worked, except it thru in the
year with the month in the same column. Is there a way to separate
the year in one column and the month in another? Your second query
didn't quite work so well. When I ran it I still got #error on
RunTot. This the error message that it gave me. The expression you
entered as a query parameter produce this error: "The object doesn't
contain the Automation object 'Enter Year." Thanks again for you help.

I create a table called Test. I then created 2 queries. The field
names are slightly different but you should be able to figure them out.

I actually created 2 running tot columns. First col is a running date
between dates. The other is a running sum between months. The reason
this was done is because there is a group on Idate, thus making a totals
record for each date.

QueryTest1
SELECT Test.IDate, Test.Rep, Sum(Test.Price) AS SumPrice, Year([Idate])
AS YearDate, Month([Idate]) AS MonDate
FROM Test
GROUP BY Test.IDate, Test.Rep, Year([Idate]), Month([Idate]);

QueryTest2
SELECT QueryTest1.IDate, QueryTest1.Rep, QueryTest1.YearDate,
QueryTest1.MonDate, QueryTest1.SumPrice,
NZ(DSum("SumPrice","QueryTest1","Idate < #" & [Idate] & "#"),0) AS
RunTotByDate, NZ(DSum("SumPrice","QueryTest1","Year([Idate]) &
Month([Idate]) < " & Year([Idate]) & Month([Idate])),0) AS RunTotByMonth
FROM QueryTest1
WHERE (((QueryTest1.Rep)=[Enter Rep]) AND ((QueryTest1.YearDate)=[Enter
Year]));- Hide quoted text -

- Show quoted text -
Thanks Salad. The queries worked, but I think the calculation is
wrong. Shouldn't my first record SumPrice be the same as RunTotByDate
and RunTotMonth to start with? Would it be possible to email part of
the table? I don't know where the numbers are pulling from but I
don't believe they are correct. I would greatly appreciate it. Thanks.

Jun 21 '07 #9
JJM0926 wrote:
On Jun 21, 1:07 pm, salad <o...@vinegar.comwrote:
>>JJM0926 wrote:
>>>On Jun 20, 5:11 pm, salad <o...@vinegar.comwrote:
>>>>JJM0926 wrote:
>>>>>On Jun 20, 10:02 am, salad <o...@vinegar.comwrote:
>>>>>>JJM0926 wrote:
>>>>>>>I'm trying to create a running totals query in access 97. I have
>>>followed the directions on how to do it from Microsofts website
>>>article id 138911. I took their code they had and replaced it with my
>>>fields. When I try to run it I get #errors in my RunTot column. I'm
>>>kinda new to this. Not sure if maybe I mistyped something wrong or is
>>>there a better way to do this? I have pasted the code. Any help would
>>>be greatly appreciated. Thanks.
>>>>>>>SELECT [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
>>>Rep], DatePart("yyyy",[Inbound Date]) AS AYear, DatePart("m",[Inbound
>>>Date]) AS AMonth, DSum("Contract Price","Quotes &
>>>Orders","Datepart('m',[Inbound Date])<=" & [Amonth] & "And
>>>Datepart('yyyy',[Inbound date])<=" & [ayear] & "") AS RunTot,
>>>Format([Inbound Date],"mmm") AS FDate
>>>>>>>FROM [Quotes & Orders]
>>>>>>>WHERE (((DatePart("yyyy",[Inbound Date]))=[Enter Year]))
>>>GROUP BY [Quotes & Orders].[Inbound Date], [Quotes & Orders].[Sales
>>>Rep], DatePart("yyyy",[Inbound Date]), DatePart("m",[Inbound Date]),
>>>Format([Inbound Date],"mmm")
>>>HAVING ((([Quotes & Orders].[Inbound Date]) Is Not Null) AND (([Quotes
>>>& Orders].[Sales Rep])=[Enter Salesman]))
>>>ORDER BY [Quotes & Orders].[Inbound Date], DatePart("yyyy",[Inbound
>>>Date]), DatePart("m",[Inbound Date]), Format([Inbound Date],"mmm");
>>>>>>AYear and Amonth haven't been defined when using them in dsum. BTW, why
>>are you using DatePart when Year(Datefield) and Month(Datefield) is more
>>readable and does the same thing?
>>>>>>The more I look at your query the bigger the mess it becomes. And your
>>orderby line is goofy.
>>>>>>I'd suggest you create a query that creates AYear and Amonth columns and
>>asks for the salesperson and year and does any and all filtering (Ex:
>>Query1). Then create another query (Query2) and make the first query
>>the data table you total and group on.- Hide quoted text -
>>>>>>- Show quoted text -
>>>>>This is the method that I got from Microsoft's website. I'm just
>trying to figure out why I am getting the #error in my RunTot column.
>As I mentioned I'm kinda new to access and sql statements. All I did
>was take Microsoft's code and change them to match my column
>headings. Thanks.
>>>>I assume there can be multiple records for the inbound date for a sales rep.
>>>>Query1. This select all of the records and rolls up the totals for the
rep you filter on by the inbound date.
SELECT [Inbound Date], [Sales Rep], Year([Inbound Date]) &
Month([Inbound Date]) As YyyyMm, Sum(Contract Price) As CPSum
FROM [Quotes & Orders]
WHERE Year([Inbound Date])=[Enter Year] And [Sales Rep] = [Enter Salesman]
Group By [Inbound Date], [Sales Rep], Year([Inbound Date]) &
Month([Inbound Date])
>>>>Query2. This creates the running sum
Select [Inbound Date], [Sales Rep], YyyyMm, CPSum,
DSum("CPSum","Query1","YyyyMm < " & [YyyyMm]) As RunTot
From Query1
Order By [Inbound Date]
>>>>This is just a suggestion. Lose the spaces in your field names.
Instead of
Inbound Date or Sales Rep
use
InboundDate or SalesRep
>>>>If you work in Access for a while you'll discover you add a lot of work
and will expend a lot of energy by creating field names with spaces.- Hide quoted text -
>>>>- Show quoted text -
>>>Thanks Salad. Your first query kinda worked, except it thru in the
year with the month in the same column. Is there a way to separate
the year in one column and the month in another? Your second query
didn't quite work so well. When I ran it I still got #error on
RunTot. This the error message that it gave me. The expression you
entered as a query parameter produce this error: "The object doesn't
contain the Automation object 'Enter Year." Thanks again for you help.

I create a table called Test. I then created 2 queries. The field
names are slightly different but you should be able to figure them out.

I actually created 2 running tot columns. First col is a running date
between dates. The other is a running sum between months. The reason
this was done is because there is a group on Idate, thus making a totals
record for each date.

QueryTest1
SELECT Test.IDate, Test.Rep, Sum(Test.Price) AS SumPrice, Year([Idate])
AS YearDate, Month([Idate]) AS MonDate
FROM Test
GROUP BY Test.IDate, Test.Rep, Year([Idate]), Month([Idate]);

QueryTest2
SELECT QueryTest1.IDate, QueryTest1.Rep, QueryTest1.YearDate,
QueryTest1.MonDate, QueryTest1.SumPrice,
NZ(DSum("SumPrice","QueryTest1","Idate < #" & [Idate] & "#"),0) AS
RunTotByDate, NZ(DSum("SumPrice","QueryTest1","Year([Idate]) &
Month([Idate]) < " & Year([Idate]) & Month([Idate])),0) AS RunTotByMonth
FROM QueryTest1
WHERE (((QueryTest1.Rep)=[Enter Rep]) AND ((QueryTest1.YearDate)=[Enter
Year]));- Hide quoted text -

- Show quoted text -


Thanks Salad. The queries worked, but I think the calculation is
wrong. Shouldn't my first record SumPrice be the same as RunTotByDate
and RunTotMonth to start with? Would it be possible to email part of
the table? I don't know where the numbers are pulling from but I
don't believe they are correct. I would greatly appreciate it. Thanks.
I'm not sure if it should. The reason is that we are looking at records
"Before" the start date or "Before" the current month we are checking.
I guess it depends on adjusting it to meet your requirements. If I had
used <= instead of <, (like you did in the original post) then it should
work OK...I think.
Jun 22 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Tony Williams | last post by:
I have a database that hold s figures for each quarter. I want to create a query whereby the user can ask for the running total of the data upto the quarter they enter into a prompt. The database...
0
by: ddecoste | last post by:
I have done a bunch of looking but I am confused as to the correct way I should proceed with this problem. I have query that returns: It is sorted by ordnum then, linenum, then date and it...
1
by: u473 | last post by:
Running Totals by date misbehaving I applied to the letter the sample code given on http://support.microsoft.com/?kbid=290136 but it seems the running total breaks when the day number is less...
4
by: New Guy | last post by:
I'm trying to work with a system that somebody else built and I am confounded by the following problem: There is a table of payments and a table of charges. Each client has charges and payments...
6
by: KashMarsh | last post by:
Trying to show running totals on a report, except it needs to show one total amount and values being subtracted from it. For example, the report shows a Total Inventory amount (TotInvAmt). And...
2
by: BerkshireGuy | last post by:
I have the following code: Dim strSQL As String Dim DB As DAO.Database Dim RS As DAO.Recordset Dim intNumOfPaid, intNumOfHypoed, intNumOfNotTaken, intNumOfDeclined, intNumOfWasted,...
0
by: Frank | last post by:
A few days ago I posted a question where I asked about how I could call/run a query in an Access97 db from a Wndows Application I am writing with VS.Net 2003 in C#. I had a couple of replies...
2
by: Jana | last post by:
Using Access 97. Background: I have a main report called rptTrustHeader with a subreport rptTrustDetails in the Details section of the main report. The main report is grouped by MasterClientID. ...
3
by: mochatrpl | last post by:
I am looking for a way to make a query / report display the running average for total dollars. I have already set up a query to provide totals dollars per day from which a report graphly shows...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.