By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,635 Members | 2,243 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,635 IT Pros & Developers. It's quick & easy.

Dcount report prints correct data but prints once for each record it checks.

P: n/a
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 <=[Enter Date]. 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
values. Again the values are correct, but for every record (it
seems) that is checked, the report prints the report. So if the
query checks 480 records, the report values show up in the report 480
times.

paramQueryDate is the query with the <=[Enter Date] parameter.
TestInfo is a table the paramQueryDate is created from.

In the code examples below, I have used both the table name and the
query name between the middle quotes for the source. I have also
tried it with and without the [DateTestReturned] field included in the
Where condition.
[Enter Date] in the report header reflects the date entered correctly.

The dcounts in the textboxes are:

To Total Academic Makeups:
=DCount("[TestType] + [Returned] + [Expired] +
[DateTestReturned] ","paramQueryDate","[TestType]=1 AND
[Returned]=true AND [Expired] = false and [DateTestReturned] <=
[Enter Date]")

The other textbox dcounts are similar to this and return correct
values, but no matter how I set things up, the darned report still
prints once for what seems is every record checked.

Hiding duplicate values doesn't matter; lines and labels still show up
even though the textboxes do not. I have tried code combinations
without any recordsource identified for the report. Also tried using
the table and then the query as the recordsource (both return correct
values). The width of the report is only 6.625 inches (not too wide
but I believe the problem has more to do with the recordsource and
such).

Everything is right except for the way the report prints out. I'm
sure some will suggest there are more elegant ways to achieve these
results but this should be working. I don't get it. What am I
missing?
Mike
Nov 13 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Not sure about some things mentioned in your post. But, I did notice
the DCount() is set up incorrectly. Try this instead:

=DCount("*","paramQueryDate","[TestType]=1 AND
[Returned]=true AND [Expired] = false and [DateTestReturned] <=
[Enter Date]")

Your first parameter should be a field name or the asterisk 'cuz the
explanation of DCount() is:

Count the 1st parameter, in the 2nd parameter, where the criteria for
counting is in the 3rd parameter.

Your first parameter:

[TestType] + [Returned] + [Expired] + [DateTestReturned]

would parse to something like this:

1 + (-1) + 0 + 38289

====

I can't understand the rest of your post, 'cuz it looks like your not
using expressions as they are generally used in this newsgroup.

Are you referring to Access Report objects as "reports," or are you
using the word report for something else?

"...for every record [...] that is checked, the report prints the
report." Huh?

How is a record checked? Is there VBA code in the report that tries to
print itself?

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQYHz5IechKqOuFEgEQKGmwCfekT5Wj7FjvoeRSIH1YaP4/4zTVYAn0ZB
D9kLqNp9is4mdKQT45YOKuih
=zvyw
-----END PGP SIGNATURE-----
Mike Conklin wrote:
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 <=[Enter Date]. 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
values. Again the values are correct, but for every record (it
seems) that is checked, the report prints the report. So if the
query checks 480 records, the report values show up in the report 480
times.

paramQueryDate is the query with the <=[Enter Date] parameter.
TestInfo is a table the paramQueryDate is created from.

In the code examples below, I have used both the table name and the
query name between the middle quotes for the source. I have also
tried it with and without the [DateTestReturned] field included in the
Where condition.
[Enter Date] in the report header reflects the date entered correctly.

The dcounts in the textboxes are:

To Total Academic Makeups:
=DCount("[TestType] + [Returned] + [Expired] +
[DateTestReturned] ","paramQueryDate","[TestType]=1 AND
[Returned]=true AND [Expired] = false and [DateTestReturned] <=
[Enter Date]")

The other textbox dcounts are similar to this and return correct
values, but no matter how I set things up, the darned report still
prints once for what seems is every record checked.

Hiding duplicate values doesn't matter; lines and labels still show up
even though the textboxes do not. I have tried code combinations
without any recordsource identified for the report. Also tried using
the table and then the query as the recordsource (both return correct
values). The width of the report is only 6.625 inches (not too wide
but I believe the problem has more to do with the recordsource and
such).

Everything is right except for the way the report prints out. I'm
sure some will suggest there are more elegant ways to achieve these
results but this should be working. I don't get it. What am I
missing?
Mike


Nov 13 '05 #2

P: n/a
Thanks MG for responding to my post. I changed the first parameter to
an asterisk as you suggested but got the same results.

To clarify about the "report printing the report." The complete
reported values (in print preview) take up about 1/3 of the page. All
the values print twice on each page. So everything in the example below
will repeat twice on the same page. If there are 80 records (tests)
being evaluated, all the information below will appear twice on 40
pages. It looks like this and just repeats, in this case, 80 times:

Academic 40 Pending 0
Distance Ed 15 Expired 5
Placement 20 Total Tests Submitted 80
Total 75

The records are checked in the text boxes only by the dcount function,
nothing else, no vb code.

What I have now is:

paramQueryDate for the record source; <=[Enter Date] is the parameter.

dcounts for the textboxes, all of which are similar to:
=DCount("*","paramQueryDate","[TestType]=1 AND [Returned]=true AND
[Expired] = false and [DateTestReturned] <= [Enter Date]")

I have another report object that this is based on. It's nearly
identical except that there is no record source and no parameter query
(based on a table) and it works perfectly. It simply dcounts all the
records (there is no date option like the one I'm working on). When I
place the table it looks to in the record source, I get the same
repeating data like I'm getting now. If I remove the record source for
the report object you're helping me with, the report pops up immediately
with #error in the text boxes. This makes sense and I understand why
this occurs, dcount is not seeing the parameter it needs (the query does
not actually run from the 2nd dcount parameter).

Do I need a filter here that will present me with a date parameter? If
so, could you give me some direction?
Thanks again.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Can you post the SQL of the query? My guess about the query's columns:

SELECT [Type], Count(*) As TypeCount

or

SELECT [Type], Sum(Students) As TypeSum

My guess is: you are duplicating the results of the query w/ the
DCount() function as the controls' ControlSource, or, your query is
retrieving too many records 'cuz of bad design (joins are wrong, or you
should be using DISTINCTROW or GROUP BY).

Your report's Detail section should hold the [Type] and Count/Sum
fields. The "Total" field should be in a section footer.

If you want 2 columns on the report you will have to indicate that in
the File > Print Setup > Columns (tab) > Column Layout (section). Read
the Access help article "Set page setup options for printing" and
"Customize a multiple-column report" for more info on multi-column
reports.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQYMuDYechKqOuFEgEQJLIgCgxAx6tLDU6gN+nuVeQ+SBAX oi6A8AoLmh
dBdEta8sFkMzI8EAU+5iRXTc
=Mp1+
-----END PGP SIGNATURE-----
Mike Conklin wrote:
Thanks MG for responding to my post. I changed the first parameter to
an asterisk as you suggested but got the same results.

To clarify about the "report printing the report." The complete
reported values (in print preview) take up about 1/3 of the page. All
the values print twice on each page. So everything in the example below
will repeat twice on the same page. If there are 80 records (tests)
being evaluated, all the information below will appear twice on 40
pages. It looks like this and just repeats, in this case, 80 times:

Academic 40 Pending 0
Distance Ed 15 Expired 5
Placement 20 Total Tests Submitted 80
Total 75

The records are checked in the text boxes only by the dcount function,
nothing else, no vb code.

What I have now is:

paramQueryDate for the record source; <=[Enter Date] is the parameter.

dcounts for the textboxes, all of which are similar to:
=DCount("*","paramQueryDate","[TestType]=1 AND [Returned]=true AND
[Expired] = false and [DateTestReturned] <= [Enter Date]")

I have another report object that this is based on. It's nearly
identical except that there is no record source and no parameter query
(based on a table) and it works perfectly. It simply dcounts all the
records (there is no date option like the one I'm working on). When I
place the table it looks to in the record source, I get the same
repeating data like I'm getting now. If I remove the record source for
the report object you're helping me with, the report pops up immediately
with #error in the text boxes. This makes sense and I understand why
this occurs, dcount is not seeing the parameter it needs (the query does
not actually run from the 2nd dcount parameter).

Do I need a filter here that will present me with a date parameter? If
so, could you give me some direction?


Nov 13 '05 #4

P: n/a
MG,

Here is the SQL code view of the paramQueryDate query object in my
Access 2000 database:

SELECT TestInfo.TestType, TestInfo.Returned, TestInfo.Expired,
TestInfo.DateTestReturned, TestInfo.SpecialtyType
FROM TestInfo
WHERE (((TestInfo.DateTestReturned)<=[Enter Date]));
The <=[Enter Date] parameter is in the Criteria line.

Repeating here for your convenience, the dcounts in the detail
section:
Academic, Distance Ed, and Placement textbox dcount codes are
identical except for [TestType]number:

=DCount("*","paramQueryDate","[TestType]=1 AND [Returned]=true
AND[Expired] = false and [DateTestReturned] <= [Enter Date]")

The textbox below these simply sums the total of the 3 textbox values.
There is nothing in the section footer. The textboxes with the
dcounts are just placed in the detail section.

I tried removing the [DateTestReturned] field from the 3rd parameter
in the dcount code above, but the data still repeats in the report.

I thought this would be an easy report to set up since it's identical
to the one that works perfectly. Didn't realize specifying a
parameter would be so problematic!

MGFoster <me@privacy.com> wrote in message news:<06****************@newsread3.news.pas.earthl ink.net>...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Can you post the SQL of the query? My guess about the query's columns:

SELECT [Type], Count(*) As TypeCount

or

SELECT [Type], Sum(Students) As TypeSum

My guess is: you are duplicating the results of the query w/ the
DCount() function as the controls' ControlSource, or, your query is
retrieving too many records 'cuz of bad design (joins are wrong, or you
should be using DISTINCTROW or GROUP BY).

Your report's Detail section should hold the [Type] and Count/Sum
fields. The "Total" field should be in a section footer.

If you want 2 columns on the report you will have to indicate that in
the File > Print Setup > Columns (tab) > Column Layout (section). Read
the Access help article "Set page setup options for printing" and
"Customize a multiple-column report" for more info on multi-column
reports.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQYMuDYechKqOuFEgEQJLIgCgxAx6tLDU6gN+nuVeQ+SBAX oi6A8AoLmh
dBdEta8sFkMzI8EAU+5iRXTc
=Mp1+
-----END PGP SIGNATURE-----
Mike Conklin wrote:
Thanks MG for responding to my post. I changed the first parameter to
an asterisk as you suggested but got the same results.

To clarify about the "report printing the report." The complete
reported values (in print preview) take up about 1/3 of the page. All
the values print twice on each page. So everything in the example below
will repeat twice on the same page. If there are 80 records (tests)
being evaluated, all the information below will appear twice on 40
pages. It looks like this and just repeats, in this case, 80 times:

Academic 40 Pending 0
Distance Ed 15 Expired 5
Placement 20 Total Tests Submitted 80
Total 75

The records are checked in the text boxes only by the dcount function,
nothing else, no vb code.

What I have now is:

paramQueryDate for the record source; <=[Enter Date] is the parameter.

dcounts for the textboxes, all of which are similar to:
=DCount("*","paramQueryDate","[TestType]=1 AND [Returned]=true AND
[Expired] = false and [DateTestReturned] <= [Enter Date]")

I have another report object that this is based on. It's nearly
identical except that there is no record source and no parameter query
(based on a table) and it works perfectly. It simply dcounts all the
records (there is no date option like the one I'm working on). When I
place the table it looks to in the record source, I get the same
repeating data like I'm getting now. If I remove the record source for
the report object you're helping me with, the report pops up immediately
with #error in the text boxes. This makes sense and I understand why
this occurs, dcount is not seeing the parameter it needs (the query does
not actually run from the 2nd dcount parameter).

Do I need a filter here that will present me with a date parameter? If
so, could you give me some direction?

Nov 13 '05 #5

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ah... I see how you've set up your report: you've put TextBoxes in the
Detail section for each TestType and the TestType Name in the TextBoxes'
Label. Like this:

Label ControlSource
------- --------------
Academic =Dcount("*","paramQueryDate","TestType=1 And ... etc.
Distance Ed =Dcount("*","paramQueryDate","TestType=2 And ... etc.
Placement =Dcount("*","paramQueryDate","TestType=3 And ... etc.
Total =txtAcademic + txtDistanceEd + Placement
If so, it would be better to do away w/ this format and use a "usual"
report format.

Change the query to something like this:

Query1 (add the TestType Description):
PARAMETERS [Enter Date] DateTime;
SELECT I.TestType, T.TestTypeDescription, Returned, Expired,
DateTestReturned, SpecialtyType
FROM TestInfo AS I INNER JOIN TestTypes As T
ON I.TestType = T.TestType
WHERE DateTestReturned<=[Enter Date]

If this query is just for this report, then change it to something like
this:

Query2 (summarize everything in the query):
PARAMETERS [Enter Date] DateTime;
SELECT I.TestType, T.TestTypeDescription, Count(*) AS TypeCount,
Count(Returned) As ReturnedCount, Count(Expired) As ExpiredCount
FROM TestInfo AS I INNER JOIN TestTypes As T
ON I.TestType = T.TestType
WHERE DateTestReturned<=[Enter Date]
GROUP BY I.TestType, T.TestTypeDescription

This assumes there is a table "TestTypes" w/ columns
TestType (AutoNumber) and TestTypeDescription (Text)

with values like this:

TestType TestTypeDescription
1 Academic
2 Distance Ed
3 Placement
... etc. ...

For Query1 use the Report Wizard & select the Summary report option.

For Query2 use the Report Wizard and create a "normal" report.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQYUvaoechKqOuFEgEQLbEgCfV7xudxrqEHBm/qijyW6ZxCKYlwkAoNqF
kazytclk1tE7zduBthE49gbJ
=cbJS
-----END PGP SIGNATURE-----
Mike Conklin wrote:
MG,

Here is the SQL code view of the paramQueryDate query object in my
Access 2000 database:

SELECT TestInfo.TestType, TestInfo.Returned, TestInfo.Expired,
TestInfo.DateTestReturned, TestInfo.SpecialtyType
FROM TestInfo
WHERE (((TestInfo.DateTestReturned)<=[Enter Date]));
The <=[Enter Date] parameter is in the Criteria line.

Repeating here for your convenience, the dcounts in the detail
section:
Academic, Distance Ed, and Placement textbox dcount codes are
identical except for [TestType]number:

=DCount("*","paramQueryDate","[TestType]=1 AND [Returned]=true
AND[Expired] = false and [DateTestReturned] <= [Enter Date]")

The textbox below these simply sums the total of the 3 textbox values.
There is nothing in the section footer. The textboxes with the
dcounts are just placed in the detail section.

I tried removing the [DateTestReturned] field from the 3rd parameter
in the dcount code above, but the data still repeats in the report.

I thought this would be an easy report to set up since it's identical
to the one that works perfectly. Didn't realize specifying a
parameter would be so problematic!

MGFoster <me@privacy.com> wrote in message news:<06****************@newsread3.news.pas.earthl ink.net>...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Can you post the SQL of the query? My guess about the query's columns:

SELECT [Type], Count(*) As TypeCount

or

SELECT [Type], Sum(Students) As TypeSum

My guess is: you are duplicating the results of the query w/ the
DCount() function as the controls' ControlSource, or, your query is
retrieving too many records 'cuz of bad design (joins are wrong, or you
should be using DISTINCTROW or GROUP BY).

Your report's Detail section should hold the [Type] and Count/Sum
fields. The "Total" field should be in a section footer.

If you want 2 columns on the report you will have to indicate that in
the File > Print Setup > Columns (tab) > Column Layout (section). Read
the Access help article "Set page setup options for printing" and
"Customize a multiple-column report" for more info on multi-column
reports.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQYMuDYechKqOuFEgEQJLIgCgxAx6tLDU6gN+nuVeQ+SBAX oi6A8AoLmh
dBdEta8sFkMzI8EAU+5iRXTc
=Mp1+
-----END PGP SIGNATURE-----
Mike Conklin wrote:

Thanks MG for responding to my post. I changed the first parameter to
an asterisk as you suggested but got the same results.

To clarify about the "report printing the report." The complete
reported values (in print preview) take up about 1/3 of the page. All
the values print twice on each page. So everything in the example below
will repeat twice on the same page. If there are 80 records (tests)
being evaluated, all the information below will appear twice on 40
pages. It looks like this and just repeats, in this case, 80 times:

Academic 40 Pending 0
Distance Ed 15 Expired 5
Placement 20 Total Tests Submitted 80
Total 75

The records are checked in the text boxes only by the dcount function,
nothing else, no vb code.

What I have now is:

paramQueryDate for the record source; <=[Enter Date] is the parameter.

dcounts for the textboxes, all of which are similar to:
=DCount("*","paramQueryDate","[TestType]=1 AND [Returned]=true AND
[Expired] = false and [DateTestReturned] <= [Enter Date]")

I have another report object that this is based on. It's nearly
identical except that there is no record source and no parameter query
(based on a table) and it works perfectly. It simply dcounts all the
records (there is no date option like the one I'm working on). When I
place the table it looks to in the record source, I get the same
repeating data like I'm getting now. If I remove the record source for
the report object you're helping me with, the report pops up immediately
with #error in the text boxes. This makes sense and I understand why
this occurs, dcount is not seeing the parameter it needs (the query does
not actually run from the 2nd dcount parameter).

Do I need a filter here that will present me with a date parameter? If
so, could you give me some direction?

Nov 13 '05 #6

P: n/a
MG,
I think I figured this thing out. It turned out to be a pretty simple
solution.

First I used paramQueryDate as the recordsource with the <=[Enter
Date]parameter. In the textbox controls with the dcounts, I added
[DateTestReturned]<=[Enter Date] to the WHERE condition. I also
shortened the code up by using the asterisks as you suggested.

Then (this is the simple part), I moved everything out of the Detail
section into the Header. Voila. I have the correct data and it does
not repeat. The footer section will work as well. Makes sense now;
it doesn't repeat because it isn't in the Detail section. The other
report worked with dcounts in detail section because there is no
recordsource specified. Once a recordsource is specified in the
report properties, it apparently changes the way the detail section
reads the records.

Thanks MG for all your help. It helped me get reaquainteed with VB
and Sql in the search for this solution (it had been awhile).

Mike C.
MGFoster <me@privacy.com> wrote in message news:<wc************@newsread3.news.pas.earthlink. net>...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ah... I see how you've set up your report: you've put TextBoxes in the
Detail section for each TestType and the TestType Name in the TextBoxes'
Label. Like this:

Label ControlSource
------- --------------
Academic =Dcount("*","paramQueryDate","TestType=1 And ... etc.
Distance Ed =Dcount("*","paramQueryDate","TestType=2 And ... etc.
Placement =Dcount("*","paramQueryDate","TestType=3 And ... etc.
Total =txtAcademic + txtDistanceEd + Placement
If so, it would be better to do away w/ this format and use a "usual"
report format.

Change the query to something like this:

Query1 (add the TestType Description):
PARAMETERS [Enter Date] DateTime;
SELECT I.TestType, T.TestTypeDescription, Returned, Expired,
DateTestReturned, SpecialtyType
FROM TestInfo AS I INNER JOIN TestTypes As T
ON I.TestType = T.TestType
WHERE DateTestReturned<=[Enter Date]

If this query is just for this report, then change it to something like
this:

Query2 (summarize everything in the query):
PARAMETERS [Enter Date] DateTime;
SELECT I.TestType, T.TestTypeDescription, Count(*) AS TypeCount,
Count(Returned) As ReturnedCount, Count(Expired) As ExpiredCount
FROM TestInfo AS I INNER JOIN TestTypes As T
ON I.TestType = T.TestType
WHERE DateTestReturned<=[Enter Date]
GROUP BY I.TestType, T.TestTypeDescription

This assumes there is a table "TestTypes" w/ columns
TestType (AutoNumber) and TestTypeDescription (Text)

with values like this:

TestType TestTypeDescription
1 Academic
2 Distance Ed
3 Placement
... etc. ...

For Query1 use the Report Wizard & select the Summary report option.

For Query2 use the Report Wizard and create a "normal" report.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQYUvaoechKqOuFEgEQLbEgCfV7xudxrqEHBm/qijyW6ZxCKYlwkAoNqF
kazytclk1tE7zduBthE49gbJ
=cbJS
-----END PGP SIGNATURE-----

Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.