473,655 Members | 3,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sum Query

266 Contributor
Hi all,

My goal is to run a report for every month. The information i want in the report is the sum of a field. Actually 6 different fields. I have a query with the following code

Expand|Select|Wrap|Line Numbers
  1. SELECT Sum(IIf([master.REPAIR],1,0)) AS SumOfREPAIR, Sum(IIf([master.REPLACE],1,0)) AS SumOfREPLACE, Sum(IIf([master.remove],1,0)) AS SumOfREMOVE, Sum(IIf([master.install],1,0)) AS SumOfINSTALL, Sum(IIf([master.maintenance],1,0)) AS SumOfMAINTENANCE, Sum(IIf([master.TEMPDISCONNECT],1,0)) AS SumOfTEMPDISCONNECT, Master.JOBTYPE
  2. FROM Master
  3. WHERE (((Master.COMPLETEDINFIELD) Is Not Null And (Master.COMPLETEDINFIELD) Like [Please Enter Month ex- 9/*/*]))
  4. GROUP BY Master.JOBTYPE;
This works great when i run the query, but i need to report on these numbers using a specific date range. Since the completedinfiel d, field is using a where clause it will not show and therefore cannot use it in my report. Is there a better way to do this? Thanks for the help.

I have attached a sample of my report.
Attached Files
File Type: pdf Report.pdf (9.8 KB, 200 views)
Jul 18 '14 #1
34 1632
Seth Schrock
2,965 Recognized Expert Specialist
What I would do is create a form that has two textboxes in which you can enter a starting and ending date. Then have your query reference the form for your criteria. If you need the date range on your report, you can pass the values to the report using the report's OpenArgs property or just reference the form in your report's OnLoad event and assign the values to a control in your header or something like that.
Jul 18 '14 #2
didacticone
266 Contributor
I think in concept i understand what your saying. Should the textboxes be linked to fields in the underlying table? And by doing this it would filter my report based on that date range? Could you possibly give me an example? I appreciate your help.
Jul 18 '14 #3
Seth Schrock
2,965 Recognized Expert Specialist
Neither the form nor the two textboxes would be bound. For ease of illustration, I'll name my form frmSearch and my two textboxes txtStart and txtEnd. Your query would then be
Expand|Select|Wrap|Line Numbers
  1. SELECT Sum(IIf([master.REPAIR],1,0)) AS SumOfREPAIR
  2. , Sum(IIf([master.REPLACE],1,0)) AS SumOfREPLACE
  3. , Sum(IIf([master.remove],1,0)) AS SumOfREMOVE
  4. , Sum(IIf([master.install],1,0)) AS SumOfINSTALL
  5. , Sum(IIf([master.maintenance],1,0)) AS SumOfMAINTENANCE
  6. , Sum(IIf([master.TEMPDISCONNECT],1,0)) AS SumOfTEMPDISCONNECT
  7. , Master.JOBTYPE
  8. FROM Master
  9. WHERE COMPLETEDINFIELD Is Not Null 
  10. And COMPLETEDINFIELD Between Forms!frmSearch!txtStart and Forms!frmSearch!txtEnd
  11. GROUP BY Master.JOBTYPE;
As far as getting the date range into the report, I would recommend the OpenArgs method. Just put a button on your form (frmSearch as I named it) that runs the report using the DoCmd.OpenRepor t method and add the text you want in the OpenArgs argument. Then, in your report's On_Load event, you can assign this value to a textbox or a label's caption.
Expand|Select|Wrap|Line Numbers
  1. Me.txtHeader = Me.OpenArgs
Jul 18 '14 #4
didacticone
266 Contributor
I have created the form and the button to open the report as you said. When i click the button the report displays a box the says "completedinfie ld" with a text box under it and i can hit ok or cancel. It does seem as though it is querying the date range properly. Is there a reason this box is coming up. Have i dont something wrong?
Jul 18 '14 #5
Seth Schrock
2,965 Recognized Expert Specialist
Make sure that the field name is typed correctly. Basically, when a query doesn't recognise a field, it asks for its value if it hasn't already been set in the query.
Jul 18 '14 #6
didacticone
266 Contributor
my understanding is that when using a where clause it cannot be displayed in the report? is this correct and why this is possibly happening?
Jul 18 '14 #7
Seth Schrock
2,965 Recognized Expert Specialist
The fields do not display. They are only criteria. However, if the same field is included in the SELECT portion of the query, then it does display. However, since you are using an aggregate query (Sum function), you would also have to include it in the GROUP BY clause which would group by the date. I think that you could group it based on the month, but this still doesn't allow you filter your results inside the report.
Jul 18 '14 #8
didacticone
266 Contributor
That was my initial conundrum. I want that field to be included but as you said i would have to include it in the group by which is something i do not want to do. any ideas?
Jul 18 '14 #9
Seth Schrock
2,965 Recognized Expert Specialist
That is why I think that it would be easier to filter your results in the WHERE clause of the query. The other option would be to have the controls in your report do the summing of the data. Personally, I don't prefer this method as it seems to take longer to do that sort of thing in a report than in a query. I like to have my data just as I want it when it gets to the report instead of working with it after.

Can you post what you tried when you got the popup in post #5?
Jul 18 '14 #10

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

Similar topics

2
3425
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the new values are updated in all corresponding tables (the function of the pages in question). However, on the page that does the DB update, I also want to do some checks on the data before performing the update. Now, the problem that I am...
29
2477
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules" for when and how to use single quotes and double quotes in ASP? thanks! ---------------------- SQL = SQL & "WHERE '" & REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE("GenKTitles.
9
3122
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use SUBSTRING(ProductName, 1, CHARINDEX('(', ProductName)-2). I can get this result, but I had to use several views (totally inefficient). I think this can be done in one efficient/fast query, but I can't think of one. In the case that one query is not...
3
5382
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says there is a sample file called Ixtrasp.asp, but I could not find it in my system although I installed indexing service. I followed the steps in MSDN site to create a basic .asp query form (too long to post it here), but it always displays: No...
14
3881
by: Dave Thomas | last post by:
If I have a table set up like this: Name | VARCHAR Email | VARCHAR Age | TINYINT | NULL (Default: NULL) And I want the user to enter his or her name, email, and age - but AGE is optional. My insert would look something like:
0
3497
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list boxes do not necessarily need to have a selection made to be used in the dynamic query. In essence the form can have selections made in all or none of its list boxes to form the dynamic query I am looking to get some feedback in reference to...
15
4392
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows of students and columns of activities and the data are the students' scores in each activity. No problem, almost. The problem is that there are five classes at the moment and will be more classes (or courses) in future semesters. I don't want...
6
4839
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID SalesManName AT Alan Time
3
1958
by: cover | last post by:
I have a table with 50 fields that receive input depending on whether that input came in from a 'shaker' form or a 'conveyor' form. Input from the 'conveyor' form might populate 25 fields while input from the 'shaker' form will populate another 20-25 fields but not the same fields (however there are about 10 common fields to both). I'd thought about using two tables (one for 'conveyor' and the other for 'shaker') but thought I'd try just...
1
2039
by: accessonion | last post by:
Hi, I have finally been converted to Access as the data set I’m using grew to a ridiculous size. I am analysing one years’ worth of data and the database itself has grown to be quite large at just over 1GB with a few million rows number of rows. This looks at about 700 stations and for each stations there are many 10,000’s of rows of data, hence the need to switch to a database. I then also have an excel spreadsheet that contains some...
0
8380
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8710
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8497
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5627
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.