Solved

running count of unique values in a ms access report

Posted on 2013-11-05
4
2,384 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
My experience with Windows 10 over a one year period and suggestions for smooth operation
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

912 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

24 Experts available now in Live!

Get 1:1 Help Now