472,986 Members | 2,725 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 software developers and data experts.

Count of unique values in a report footer

SJM
I have a report that displays records of real estate properties. It is
possible for each property to appear a number of times for various reasons.
Each record however is unique. What I would like to do is display the total
of the number of unique properties in the report footer, not just a count of
the number of records. I have experimented with grouping on the property
field and using running sums but to no avail. I have also tried to determine
the unique property count by using a recordset based on the query underlying
the report in the report footer on format event, but this would not work as
it complained of not having the required parameter which did not make sense.
Maybe I could save the underlying data to a table and base the report on
that and then get a recordcount on a recordset based on the table to fill in
the unique property count field in the report. Should it be an easy thing to
display a 'unique count' in a report footer?
Nov 13 '05 #1
2 7736
Ed
SJM:

Try this out for size. It assumes that you have a table or a query as the
record source for the report and that [PropertyID] is the unique identifier
of the property and that [PropertyID] is an output column of the record
source. Create a field named txtUniqueRecs in the report footer section,
then copy this code into the On Print event.

Private Sub ReportFooter_Print(Cancel As Integer, PrintCount As Integer)
On Error Resume Next
Dim rst As DAO.Recordset
Dim strRecSource As String
Dim strSQL As String
strRecSource = Me.RecordSource
strSQL = "SELECT DISTINCT PropertyID FROM (" & strRecSource & "); "
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
If rst.BOF And rst.EOF Then
'there's no data,
'return 0
Me!txtUniqueRecs = 0
Else
rst.MoveLast
Me!txtUniqueRecs = rst.RecordCount
End If
Set rst = Nothing
End Sub

Add whatever error routine you normally use.

Good luck,
Ed

"SJM" <no****@ms.com> wrote in message
news:Ny****************@nnrp1.ozemail.com.au...
I have a report that displays records of real estate properties. It is
possible for each property to appear a number of times for various reasons. Each record however is unique. What I would like to do is display the total of the number of unique properties in the report footer, not just a count of the number of records. I have experimented with grouping on the property
field and using running sums but to no avail. I have also tried to determine the unique property count by using a recordset based on the query underlying the report in the report footer on format event, but this would not work as it complained of not having the required parameter which did not make sense. Maybe I could save the underlying data to a table and base the report on
that and then get a recordcount on a recordset based on the table to fill in the unique property count field in the report. Should it be an easy thing to display a 'unique count' in a report footer?

Nov 13 '05 #2
SJM
Ed.
This is very similar to what I tried except...
A. I used ADODB instead of DAO.
B. I referenced the underlying report query rather than the report
recordsource.
I was wanting to do something based on RecordSetClone but this is not
available in reports, but using the report's recordsource in the sql like
you outline below could be the angle I am looking for. I haven't tried it
yet, but thanks anyway, I will give it a go.

"Ed" <ed*********@cox.net> wrote in message
news:Yu%dd.6666$EZ.6012@okepread07...
SJM:

Try this out for size. It assumes that you have a table or a query as the
record source for the report and that [PropertyID] is the unique identifier of the property and that [PropertyID] is an output column of the record
source. Create a field named txtUniqueRecs in the report footer section,
then copy this code into the On Print event.

Private Sub ReportFooter_Print(Cancel As Integer, PrintCount As Integer)
On Error Resume Next
Dim rst As DAO.Recordset
Dim strRecSource As String
Dim strSQL As String
strRecSource = Me.RecordSource
strSQL = "SELECT DISTINCT PropertyID FROM (" & strRecSource & "); "
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
If rst.BOF And rst.EOF Then
'there's no data,
'return 0
Me!txtUniqueRecs = 0
Else
rst.MoveLast
Me!txtUniqueRecs = rst.RecordCount
End If
Set rst = Nothing
End Sub

Add whatever error routine you normally use.

Good luck,
Ed


Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: L Mehl | last post by:
Different users of the app will want or not want to see report footer ( appears as a separate page). I can make the section invisible with a DLookup of a Y or N value from a 'parameters' table ...
1
by: Steve Heath | last post by:
I have a query that provides detail for sales transactions meeting certain criteria (date, purchase type, etc.) I am creating a report based on that query, and I want to add a summary section. I...
1
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...
5
by: Cro | last post by:
Hello Access Developers, I'd like to know if it is possible to perform a count in an expression that defines a control source. My report is based on a query. In my report, I want a text box to...
3
by: Rabun | last post by:
Heres one that is giving me fits ( = = Access newbie), more than likely something simple that I blew right over . . . any help is appreciated - I have a report based on a query, with several...
5
by: Soccer5 | last post by:
Trying to Count records on a report that meet a certain criteria. Have a text box in the Report Footer that has the following in the Control Source: =Count(="S") This does not work. It...
1
by: N06149 | last post by:
I have a report based on a query. I list an Org_Type then Org_Name then the Projects associated with it. Sample of report below: Community Type...
3
by: isoquin | last post by:
I've looked, and not found much. I have a text field in a form named , which acquires its data through a control source of =getLocation() the getLocation() function returns a DLookup, which...
1
newnewbie
by: newnewbie | last post by:
Hi, Could somebody please help me with VBA code to count unique values in a Report? Report is based on a query that has grouped values. Basically, I would like to use formula...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.