473,604 Members | 2,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The Dreaded DCOUNT Function in a Report

17 New Member
Good afternoon,

I am attempting to count only those records within a report, which is based on a query, where Status is equal to Closed. I have tried multiple variations of DCOUNT but am continuously receiving the "#ERROR" message in the control source box on the report. Below is the expression that I have tried to use and modify numerous times. Don't know if i'm just simply having syntax issues or my formula is just wrong. I did attempt to use a suggested SQL statement which is also below but I don't know how to get the result of that SQL statement embedded in my Report. Any advice is greatly appreciated. THANKS!

My proposed statement:
Expand|Select|Wrap|Line Numbers
  1. =DCount("[Status]","ROA_Imaging_QueWeb_LINKED_Query","[Status] = 'Closed' ")
My proposed SQL statement:
Expand|Select|Wrap|Line Numbers
  1. SELECT Status, COUNT(*)
  2. FROM ROA Imaging QueWeb - LINKED
  3. WHERE Status = "Closed"
  4. GROUP BY Status;
Oct 4 '07 #1
36 11409
NeoPa
32,566 Recognized Expert Moderator MVP
Welcome to TheScripts.

The SQL has embedded spaces in the query name without the [] delimiters.
The name of the dataset differs between the SQL & the expression.
Try resolving these issues and seeing where that gets you.
Oct 5 '07 #2
JConsulting
603 Recognized Expert Contributor
Good afternoon,

I am attempting to count only those records within a report, which is based on a query, where Status is equal to Closed. I have tried multiple variations of DCOUNT but am continuously receiving the "#ERROR" message in the control source box on the report. Below is the expression that I have tried to use and modify numerous times. Don't know if i'm just simply having syntax issues or my formula is just wrong. I did attempt to use a suggested SQL statement which is also below but I don't know how to get the result of that SQL statement embedded in my Report. Any advice is greatly appreciated. THANKS!

My proposed statement:
Expand|Select|Wrap|Line Numbers
  1. =DCount("[Status]","ROA_Imaging_QueWeb_LINKED_Query","[Status] = 'Closed' ")
My proposed SQL statement:
Expand|Select|Wrap|Line Numbers
  1. SELECT Status, COUNT(*)
  2. FROM ROA Imaging QueWeb - LINKED
  3. WHERE Status = "Closed"
  4. GROUP BY Status;
Use your proposed statement in the On_Format event of the report for the appropriate section.
Expand|Select|Wrap|Line Numbers
  1. me.mytextbox = nz(DCount("[Status]","ROA_Imaging_QueWeb_LINKED_Query","[Status] Like 'Closed' "),0)
  2.  
J
Oct 5 '07 #3
bmyers
17 New Member
Thanks for your quick assistance. And you're right, they were different. I have been doing "trial and error" quite a bit and forgot to change the SQL statement back to using the query. If I indeed have the below now corrected with formatting, my goal is really to only use one means of putting the total on the finished report. Whether it be using the embedded SQL statement, which I'm not sure how to even embedd the statement within a report, or use the "Dcount" option as a control source with a text box. Of course at this point neither is working for me...HA! How does they look now? Thanks for your assistance.

Expand|Select|Wrap|Line Numbers
  1. =DCount("[Status]","ROA_Imaging_QueWeb_LINKED_Query","[Status] = 'Closed' ")
Expand|Select|Wrap|Line Numbers
  1. SELECT Status,COUNT(*)
  2. FROM ROA_Imaging_QueWeb_LINKED_Query
  3. WHERE Status = "Closed"
  4. GROUP BY Status;
Oct 5 '07 #4
NeoPa
32,566 Recognized Expert Moderator MVP
The first one (=DCount(...)) looks fine. As we have no access to what's in the query it's hard to know if it all works.
Also, as we have no understanding of where you've tried to add this already, we don't know what you have in your report.
It would typically go in a control within the Report Header (if that helps).

PS. Please try to use the [ CODE ] tags when posting code in here. It is required and is also much easier to read - therefore easier to help you.
Oct 5 '07 #5
bmyers
17 New Member
Sorry about that. Just eager to get this thing resolved. I've now decided to NOT use the query as my control. I was only using a query instead of the actual table with all of the data because the query already had filtered out the needed dates. Therefore, if I now use the table instead of the query as my control source, I will need to add another condition to the DCOUNT function to contain the dates.

Expand|Select|Wrap|Line Numbers
  1. =DCount("[Status]","ROAImagingQueWeb-LINKED","([Status]='Closed') AND ([DateReported] Between #09/16/07# AND #09/30/07#)")
However though, I also have two user supplied date fields within the report that come from the Record Source (which these fields feed the query to bring out only those records with the user-defined date constraints). In other words, when a user selects to run this report, it immediately prompts them for the Start Date and End Date which is then added to the query to spit back only the records between those dates. All that to say, is there even to way have this user-supplied info added into the DCOUNT formula, using the same dates that are entered as a result of the Record Source already being the Date Query. Perhaps something like this:

Expand|Select|Wrap|Line Numbers
  1. =DCount("[Status]","ROAImagingQueWeb-LINKED","([Status]='Closed') AND ([DateReported] Between #09/16/07# AND #09/30/07#)")
Or

Expand|Select|Wrap|Line Numbers
  1. =DCount("[Status]","ROAImagingQueWeb-LINKED","([Status]='Closed') AND ([Date Reported] Between '[Enter Period Start Date]' AND '[Enter Period End Date]')")
Oct 5 '07 #6
NeoPa
32,566 Recognized Expert Moderator MVP
No problem - just a reminder about the tags :)
I need to know where you have access to the values entered by the operator. How and where are they stored and where is the formula going in your report?
Oct 5 '07 #7
bmyers
17 New Member
The operator-entered values are a result of the query which is the Report Source of the Report. The SQL View of that query is below.

Expand|Select|Wrap|Line Numbers
  1. SELECT [ROAImagingQueWeb-LINKED].[Reference #], [ROAImagingQueWeb-LINKED].[Date Reported], [ROAImagingQueWeb-LINKED].Customer, [ROAImagingQueWeb-LINKED].Status, [ROAImagingQueWeb-LINKED].Priority, [ROAImagingQueWeb-LINKED].PROBLEM, [ROAImagingQueWeb-LINKED].Owner
  2. FROM [ROAImagingQueWeb-LINKED]
  3. WHERE ((([ROAImagingQueWeb-LINKED].[Date Reported]) Between [Enter Period Start Date] And [Enter Period End Date]))
  4. ORDER BY [ROAImagingQueWeb-LINKED].[Date Reported];
  5.  
The 'Enter Period Start Date' and 'Enter Period End Date' are then user-supplied when the query is run against the main table, ROAImagingQueWe b-LINKED, which is a linked table. Thus, because the Report Source is the query, when the report is run, the operator is prompted for the date constraints.

The Report then displays records from the table within those dates and performs various "counts" within the groups, by Status and by Priority. However, the issue is that the COUNT(*) function is of course counting all of the records within a particular group as it's designed to do. And in my case, it groups all of the "Tickets" (which the Main table is just Help Desk Ticket info) whether they be "Closed" or "Opened" and gives me a combined total of "Open" and "Closed" tickets. However, my goal is to add another text box that contains a count of just the "Closed" tickets.

I wonder though if because my Record Source for the Report is the Table, but my Dcount function is trying to use the Query that pullls from that Table makes a difference?
Oct 5 '07 #8
bmyers
17 New Member
Hi again folks,

Just hoping that perhaps someone could offer a few more words of advice. I definitely appreciate the help.

Brian
Oct 8 '07 #9
NeoPa
32,566 Recognized Expert Moderator MVP
Brian,

Fine to bump - I must have managed to miss this over the weekend.
However, I'm probably too short of time atm to look into this deeply but a point to ponder would be that the dates entered by the operator into the running SQL (as prompted) are not available to your code. This is one of the limitations of doing it that way.
There are solutions to this but typically they depend heavily on EXACTLY what you're trying to do. That means precision of communication becomes extra important.
I'll leave that with you for now. Let me know if you have any thoughts and I will look at it again anyway if I get some more time.
Oct 8 '07 #10

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

Similar topics

1
1535
by: Simon Matthews | last post by:
Hope someone can help an Access beginner! I've just started keeping my surgical logbook on access and it's a simple flat-file affair. I have created several queries that will list cases performed at different hospitals and reports based on the queries to print out the relavent details. What I would like to do is have a summary sheet in the Report Footer section that lists a grid of each type of procedure performed as well as the...
1
2826
by: Megan | last post by:
Hi Everybody- I've been reading some of the posts about DCOUNT, and I haven't yet found an answer; so, I'm posting this question. I have a report that I'm trying to use DCOUNT on to compute the percentages of each group. The groups are based on sports. For instance, football, soccer, baseball, basketball. I have a table of people that play these sports.
6
3312
by: Mike Conklin | last post by:
This one really has me going. Probably something silly. I'm using dcount for a report to determine the number of different types of tests proctored in a semester. My report is based on a parameter query which is the recordsource for the report. The parameter is <=. The query returns the correct amounts upto the date entered (no need for "between" dates here). There are 8 textboxes with dcounts; 2 other boxes Sum some of these
7
6343
by: kaosyeti | last post by:
hey.. i have a control in a report that needs to count the records from a table that match the parameters that the user selects when creating the report. the report is created with formquerybuilder and the parameters are department, upsource, and date. i can't get the syntax down for this dcount: =DCount("*","tblcontactdata"," Between #" & & "# And #" & & "#" & "' AND '" & "'='" & "'forms! formquerybuilder!cboxupsource'" & "' AND '"...
2
1738
by: Kaspa | last post by:
Hello I am trying to create dcount field but is not working I have tried every way possible and I can't get it to work. here is my code: =Dcount("","qryTotalscratched"," in (6,7,8,9) and between #01/01/2001# and " & ) I also tried:
1
5417
by: Sheldon Mopes | last post by:
I have read a few articles that state that a multi-user app over a network will run faster if DSum & DCount functions are replaced with SQL statements replicating the functions. As I am a novice to SQL, any suggestions would be hugely appreciated. Thanks.
2
7935
by: Wingz | last post by:
Hiya, Fairly new to Access and was wondering what the best way to perform Dcounts on groups in an Access report. For example, I have 10 employees and the different instances of jobs they can perform are either Clean, Shampoo or Vacuum. I have a query called Details that shows a history of all the jobs they have performed. On my report I want a total for each employee of how many of each job they have performed. This is what I know of...
3
4795
by: Rebekkah | last post by:
I did a search but couldn't find a question similar to mine. I need to count the values in a textbox on a report and have the count subtotal in a group footer. But I need three different counts on the same textbox because there are three possible values and I need a count on each. I can't just do a simple DCount on the table and manually define the criteria because there are many different groups that will need the counts for only that group....
5
2476
by: den4673 | last post by:
Hello, I am hoping someone can help me and tell me how to correct my problem. My report is based on an Invoice query, where each invoice has a date, amount and corresponding week number. In the report in the detail footer, I want a summary by week number for Total Invoice Amount and count of number of Invoices with zero amount. I can get the invoice total amount, howerver, the count of invoices with zero amount returns the same amount...
0
7997
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
8409
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
8065
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
8280
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5882
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
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();...
1
2434
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
1
1526
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1266
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.