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

Reports

Hi,

I have a table which contains the fields Empid, Empname, Amount, Date_check_rcvd. Now my question I want to generate a report which gives the sum of amount by month and by year thru the date of check recieved. I have a problem in writing the query where if I say sum(amount) and execute the query it gives an error saying " you tried to execute the query that does not include a specified expression Empid as part of aggregate function". I have very little experience in writing the queries. I just don't know what is wrong??can anyone help me out????
Feb 28 '07 #1
21 4969
MMcCarthy
14,534 Expert Mod 8TB
Hi,

I have a table which contains the fields Empid, Empname, Amount, Date_check_rcvd. Now my question I want to generate a report which gives the sum of amount by month and by year thru the date of check recieved. I have a problem in writing the query where if I say sum(amount) and execute the query it gives an error saying " you tried to execute the query that does not include a specified expression Empid as part of aggregate function". I have very little experience in writing the queries. I just don't know what is wrong??can anyone help me out????
When using an aggregate query (query with things like Sum, Count, Avg, etc.) you must group by all fields not being aggregated. You can't do both Month and Year in the same query.

For instance...

For the Month:
Expand|Select|Wrap|Line Numbers
  1. SELECT Empid, Empname, Sum(Amount), Month(Date_check_rcvd)
  2. FROM TableName
  3. GROUP BY Empid, Empname, Month(Date_check_rcvd);
For the Year:
Expand|Select|Wrap|Line Numbers
  1. SELECT Empid, Empname, Sum(Amount), Year(Date_check_rcvd)
  2. FROM TableName
  3. GROUP BY Empid, Empname, Year(Date_check_rcvd);
Mary
Feb 28 '07 #2
ADezii
8,834 Expert 8TB
Hi,

I have a table which contains the fields Empid, Empname, Amount, Date_check_rcvd. Now my question I want to generate a report which gives the sum of amount by month and by year thru the date of check recieved. I have a problem in writing the query where if I say sum(amount) and execute the query it gives an error saying " you tried to execute the query that does not include a specified expression Empid as part of aggregate function". I have very little experience in writing the queries. I just don't know what is wrong??can anyone help me out????
Assumptions:
__1 Table Name = Table1
__2 [Empid] AutoNumber (Primary Key)
__3 [Empname] (TEXT 50)
__4 [Amount] (CURRENCY)
__5 [Date_check_rcvd] (DATE/TIME)
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Sum(Table1.Amount) AS SumOfAmount
  2. SELECT Table1.Empname AS Employee, Sum(Table1.Amount) AS [Total Amount], Year([Date_check_rcvd]) AS Year
  3. FROM Table1
  4. GROUP BY Table1.Empname, Year([Date_check_rcvd])
  5. PIVOT Format([Date_check_rcvd],"mmm") In ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
Feb 28 '07 #3
Thank you for the reply.

I am sorry in my previous post I forgot to mention other field i.e., Memosent which of data type date/time. Now when I run the query you have given me in the post it prompts me the message saying " enter the parameter value Memosent". When I click ok on the message then the report opens.
Feb 28 '07 #4
My reply is for the post given by mmccarthy
Feb 28 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
Thank you for the reply.

I am sorry in my previous post I forgot to mention other field i.e., Memosent which of data type date/time. Now when I run the query you have given me in the post it prompts me the message saying " enter the parameter value Memosent". When I click ok on the message then the report opens.
What is this field and why do you need to include it. ADezii's example is better than mine BTW.

Mary
Feb 28 '07 #6
I even tried the code given by ADezii but it prompts the same msg saying "enter the parameter value date_check_rcvd" and also when I run the report it asks me to enter the amount,date_check_rcvd
Feb 28 '07 #7
The field is nothing but the date when the check was sent.
Feb 28 '07 #8
MMcCarthy
14,534 Expert Mod 8TB
The field is nothing but the date when the check was sent.
Can you leave it out as the date_check_rcvd is the date being used for the calculation. Another date like the memosent date will mess up all the figures.

Mary
Feb 28 '07 #9
Can you leave it out as the date_check_rcvd is the date being used for the calculation. Another date like the memosent date will mess up all the figures.

Mary
I don't think I can do that because I want all the fields in the report.
Feb 28 '07 #10
MMcCarthy
14,534 Expert Mod 8TB
Try this revised version of ADezii's code.

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Sum(amount) AS TotalAmount
  2. SELECT Empname AS Employee, Sum(amount) AS TotalAmount, Year([date_check_rcvd]) AS Year
  3. FROM TableName
  4. GROUP BY Empname, Year([date_check_rcvd])
  5. PIVOT Format([date_check_rcvd],"mmm") In ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  6.  
Mary
Feb 28 '07 #11
MMcCarthy
14,534 Expert Mod 8TB
I don't think I can do that because I want all the fields in the report.
To explain ...

We are totaling the Amount per Employee based on the Month and Year of the date the check was received. If another date is introduced then you can't calculate the figure as it will be broken down over the other date.

Mary
Feb 28 '07 #12
Try this revised version of ADezii's code.

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Sum(amount) AS TotalAmount
  2. SELECT Empname AS Employee, Sum(amount) AS TotalAmount, Year([date_check_rcvd]) AS Year
  3. FROM TableName
  4. GROUP BY Empname, Year([date_check_rcvd])
  5. PIVOT Format([date_check_rcvd],"mmm") In ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  6.  
Mary
when I run the query it gives an error saying duplicate output alias "TotalAmount"
Feb 28 '07 #13
To explain ...

We are totaling the Amount per Employee based on the Month and Year of the date the check was received. If another date is introduced then you can't calculate the figure as it will be broken down over the other date.

Mary
So, Do I need to remove the field in the query?
Feb 28 '07 #14
MMcCarthy
14,534 Expert Mod 8TB
So, Do I need to remove the field in the query?
Yes.

And the error on ADezii's was my fault. Try this...
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Sum(amount) AS SumOfAmount
  2. SELECT Empname AS Employee, Sum(amount) AS TotalAmount, Year([date_check_rcvd]) AS Year
  3. FROM TableName
  4. GROUP BY Empname, Year([date_check_rcvd])
  5. PIVOT Format([date_check_rcvd],"mmm") In ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  6.  
Mary
Feb 28 '07 #15
Yes.

And the error on ADezii's was my fault. Try this...
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Sum(amount) AS SumOfAmount
  2. SELECT Empname AS Employee, Sum(amount) AS TotalAmount, Year([date_check_rcvd]) AS Year
  3. FROM TableName
  4. GROUP BY Empname, Year([date_check_rcvd])
  5. PIVOT Format([date_check_rcvd],"mmm") In ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  6.  
Mary
As you said I have removed the field and now when I execute the query it was successful. I have created the report based on this query I mean in the report's recordsource I have given the name of this query. Now when I run the report it prompts me asking for the amount and date_check_rcvd.

And one more thing I want the report in such a way that it should prompt me saying that which month for monthly repports and which year for yeraly reports
Feb 28 '07 #16
Is there anything that I can do with the reports? I tried in various ways but could not make it up.
Feb 28 '07 #17
MMcCarthy
14,534 Expert Mod 8TB
Is there anything that I can do with the reports? I tried in various ways but could not make it up.
If that's the case then use my code rather than ADezii's and in the report open code add the criteria based on a couple of combo boxes set up with year and month number bound with month showing.

For monthly reports:

Expand|Select|Wrap|Line Numbers
  1.  
  2. DoCmd.OpenReport "ReportName", , , "Month(Date_check_rcvd)=" & Me.Combo1 & _
  3.    " AND Year(Date_check_rcvd)=" & Me.Combo2
Mar 1 '07 #18
If that's the case then use my code rather than ADezii's and in the report open code add the criteria based on a couple of combo boxes set up with year and month number bound with month showing.

For monthly reports:

Expand|Select|Wrap|Line Numbers
  1.  
  2. DoCmd.OpenReport "ReportName", , , "Month(Date_check_rcvd)=" & Me.Combo1 & _
  3.    " AND Year(Date_check_rcvd)=" & Me.Combo2
I don't think I can put combo box for the year because the reports are for future use. What if we have two textboxes for the datefrom and dateto and have 2 command buttons for month and year. So, once we enter say 1/1/2003 - 1/31/2003 and click on the month button it should give the report for that month calculating the sum of amount and same is for the year. Here my problem is I am able to generate the report monthly and yearly but I am not able to calculate the sum of amount neither monthly nor yearly. Can you help me out in this??
Mar 1 '07 #19
NeoPa
32,556 Expert Mod 16PB
Can you please try to clarify in your own mind what it is you want.
Having reviewed this thread it seems that you're introducing new and important information periodically when an answer doesn't fit your situation. This is because you haven't shared the information to start with.
It also seems that you're reluctant even to try out the answers supplied and want to introduce your own, quite incompatible, ideas along the way. This is not reasonable and makes it so much harder for our experts to help you. It's hard enough to answer complicated questions remotely as it is, never mind a question where the original poster hasn't shared the necessary information and also changes the requirement on the fly.
I will leave this thread open in case anyone feels the need to reply, but you can consider this thread closed as far as the question itself is concerned.
I suggest you get your information together and repost the question clearly, and hope that someone dares to start helping you on it.

MODERATOR.
Mar 2 '07 #20
Can you please try to clarify in your own mind what it is you want.
Having reviewed this thread it seems that you're introducing new and important information periodically when an answer doesn't fit your situation. This is because you haven't shared the information to start with.
It also seems that you're reluctant even to try out the answers supplied and want to introduce your own, quite incompatible, ideas along the way. This is not reasonable and makes it so much harder for our experts to help you. It's hard enough to answer complicated questions remotely as it is, never mind a question where the original poster hasn't shared the necessary information and also changes the requirement on the fly.
I will leave this thread open in case anyone feels the need to reply, but you can consider this thread closed as far as the question itself is concerned.
I suggest you get your information together and repost the question clearly, and hope that someone dares to start helping you on it.

MODERATOR.
Thank you for ur comments. I have got the reports to be generated.
Mar 5 '07 #21
NeoPa
32,556 Expert Mod 16PB
Though I may sound critical, I'm nevertheless pleased you managed to resolve your issues.
Mar 5 '07 #22

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

Similar topics

5
by: BStorm | last post by:
I have a transaction log file where the DataSet table's Description column is actually delimited into "subcolumns" based upon the transaction id. I would like to parse these into separate fields...
2
by: Andrew | last post by:
Hi there: I can successfully control a report's GroupLevel ControlSource property by using: ..Reports!rptEESTMT_A.GroupLevel(i).ControlSource = "CorpName" where rptEESTMT_A is the actual...
0
by: Ian | last post by:
(Sorry if I have repeated this, it did not appear the first time) I have the following code on a button. The idea is that when this button is clicked it prints several reports automatically then...
3
by: Gheaci Maschl | last post by:
Hi all! I would like to have your opinion about my problem and my proposal how to solve it: Ingredients: - BTriev database - Crystal Reports - maybe MS Access - Liinos6 (small ERP software)
1
by: KEVIN97810 | last post by:
Hello to all, I am trying to fill all my reports in a listbox but I may not need to show other reports. How do you modify this function to do that. I have losts of reports but don't want to...
2
by: B.Newman | last post by:
I've got some VB.NET code that *should* get a list of reports from an Access MDB and populate a list box with them. It doesn't detect any of the reports at all. oAccess.Reports.Count comes up as...
3
by: VMI | last post by:
I know this may not be the best NG for this, but I feel you guys know more about this than any of the other NGs. I need to build several simple reports (over 50 of them and they get their data...
12
by: Tony Ciconte | last post by:
We are evaluating the prospect of integrating and/or using Crystal Reports with some of our current products. Some of these are still in Access 97 and are running well. Since we cannot include the...
16
by: JoeW | last post by:
I'm utilizing a database that I created within MS Access within a program I've created in VB.NET. I am using the VB front end to navigate the information, but want to be able to print a report,...
3
by: joelpollock | last post by:
I'm having trouble continuously page numbering a large report in MS Access. The report is made up of three separate Access reports which I join together at the end. In the past I have opened the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.