Solved

running count of unique values in a ms access report

Posted on 2013-11-05
4
2,345 Views
Last Modified: 2013-11-17
I have a table that has a list of numbers that i would like to display a running count of unique value in a ms access report, this report has no grouping levels which makes it a bit challenging.Thanks
Database1.accdb
0
Comment
Question by:Svgmassive
4 Comments
 
LVL 10

Expert Comment

by:etech0
ID: 39625129
For a list of unique values:

SELECT DISTINCT fieldName FROM tableName;

For a count of unique values:

SELECT Count(*) AS N
FROM
(SELECT DISTINCT fieldName FROM tableName) AS T;
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39625133
is this what you are looking for

SELECT dbo_itemx.Sequencenumber, Count(dbo_itemx.Sequencenumber) AS CountOfSequencenumber
FROM dbo_itemx
GROUP BY dbo_itemx.Sequencenumber;

or maybe this is what you need

SELECT Q.Sequencenumber,
(select count(*) from
(SELECT dbo_itemx.Sequencenumber
FROM dbo_itemx
GROUP BY dbo_itemx.Sequencenumber
)  as Q1 where Q1.SequenceNumber<=Q.SequenceNumber) AS Expr1
FROM
(SELECT dbo_itemx.Sequencenumber
FROM dbo_itemx
GROUP BY dbo_itemx.Sequencenumber
) as Q;



it will help if you post a desired outcome/output
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 39625235
You could use a function, see fnUniqueRowCount() in the attached database.

Add a control to your report, set the ControlSource to:

=fnUniqueRowCount([UniqueFieldName])

Then, change the Hide Duplicates (towards the bottom of the Format tab on the Properties dialog form) property to Yes.

Then, to make sure this works in normal view, report view, and print preview, you will need to call the function from the Report Open and Report Footers Format events, with the following code:

=fnuniquerowcount(Null,True)

This will reset the counter when the report is opened or when the report footer is formatted.  The reason for the latter is that when you view the report in print preview, it runs through the report twice and if you don't reset the counter at the end of the report, the numbers will start a the last number + 1
UniqueRowCount.accdb
0
 

Author Comment

by:Svgmassive
ID: 39628243
fyed that's what i am looking,but a strange this is happening if i hide the control and hide duplicates the count is not correct.i just need it to display a total in the page footer per page
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
This article will show you how to use shortcut menus in the Access run-time environment.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now