Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / May 2008

Tip: Looking for answers? Try searching our database.

Trying to not count duplicates in a report

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
clueless - 11 May 2008 23:18 GMT
I am new to Access.  I have a field OrderID, I need it to count the total #
of orders for a daily report and a weekly report.  The problem is more than 1
employee will be dealing with each order (1 employee picks the order, another
employee verifies and loads the order on the truck), so in the 2 reports it
shows the same OrderID for both employees and counts it twice; I need it to
only count it once, and to add more confusion it might be picked and loaded
the same day or it could be picked on say Monday and loaded on Tuesday.  I
have read all the postings about duplicate counts and my head is spinning.  I
really would appreciate any help that someone can offer me.  Thanks in
advance!
Signature

clueless

Tom Wickerath - 12 May 2008 00:20 GMT
In report design view, click on View | Sorting and Grouping (I'm making the
assumption that you are using Access 2003 or earlier. If you are using Access
2007, the logic will be the same, but you'll have to find the corresponding
steps using the ribbon). Add your OrderID field to the Sorting and Grouping
dialog, with Group Header = Yes, Group Footer = No, Group On = Each Value,
Group Interval = 1 and Keep Together = Whole Group.

Expand the Report Footer section, if it has a height of zero. Add a text box
with the following calculated expression:

   =Count([OrderID])

Where OrderID is the name of the field. Make the appropriate substitution if
your field is named something else, such as [Order ID]. Make sure that the
name of this text box in not the same as the name of the any fields involved
in the expression.

Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

> I am new to Access.  I have a field OrderID, I need it to count the total #
> of orders for a daily report and a weekly report.  The problem is more than 1
[quoted text clipped - 6 lines]
> really would appreciate any help that someone can offer me.  Thanks in
> advance!
Duane Hookom - 12 May 2008 01:09 GMT
Using
 =Count([Any Non-Null Expression])
in a report footer will always count the total number of records in the
report. If the OrderID is repeated, you can add  a text box to the OrderID
header:
 Name: txtCountOrder
 Control Source: =1
 Running Sum: Over All
 Visible: No
Then add a text box to your report footer:
 Control Source: =txtCountOrder

Signature

Duane Hookom
Microsoft Access MVP

> In report design view, click on View | Sorting and Grouping (I'm making the
> assumption that you are using Access 2003 or earlier. If you are using Access
[quoted text clipped - 29 lines]
> > really would appreciate any help that someone can offer me.  Thanks in
> > advance!
Tom Wickerath - 12 May 2008 01:19 GMT
Hi Duane,

Yep, you're right. I screwed up. I had created a quicky test report that
included 65 pages, and it showed 1665 total orders. I made the incorrect
assumption that 1665 represented unique order numbers. It did not. Oops.
Thanks for the correction.

Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

> Using
>   =Count([Any Non-Null Expression])
[quoted text clipped - 7 lines]
> Then add a text box to your report footer:
>   Control Source: =txtCountOrder
Duane Hookom - 12 May 2008 02:15 GMT
I couldn't begin to count the number of times my answers have been
"clarified" by others ;-)
Signature

Duane Hookom
Microsoft Access MVP

> Hi Duane,
>
[quoted text clipped - 20 lines]
> > Then add a text box to your report footer:
> >   Control Source: =txtCountOrder
clueless - 12 May 2008 17:35 GMT
Hi.  Thanks for the quick response.  I put in =Count([Any Non-Null
Expression]) and now an enter Parameter value box pops up when I go to look
at the report.  Why is that and what do I need to do? (I am using Access 2007)
Signature

clueless

> Using
>   =Count([Any Non-Null Expression])
[quoted text clipped - 41 lines]
> > > really would appreciate any help that someone can offer me.  Thanks in
> > > advance!
Duane Hookom - 12 May 2008 22:28 GMT
My suggestion was to NOT use the =Count([...]). You need to understand that
when some suggests something like "Any Non-Null Expression" this is an
instruction like "Press Any Key". You won't find a key on your keyboard with
"Any" printed on it.

Signature

Duane Hookom
Microsoft Access MVP

> Hi.  Thanks for the quick response.  I put in =Count([Any Non-Null
> Expression]) and now an enter Parameter value box pops up when I go to look
[quoted text clipped - 45 lines]
> > > > really would appreciate any help that someone can offer me.  Thanks in
> > > > advance!
clueless - 12 May 2008 23:17 GMT
Duane, Sorry about that.  Yes, I finally figured out what you were telling me
and it works beautifully for my daily report, so I thank you.  Next, I have
to try to figure out what Ken is telling me.  I really like Access, but it is
such a challenge.  Thanks again for your help.
Signature

clueless

> My suggestion was to NOT use the =Count([...]). You need to understand that
> when some suggests something like "Any Non-Null Expression" this is an
[quoted text clipped - 50 lines]
> > > > > really would appreciate any help that someone can offer me.  Thanks in
> > > > > advance!
Ken Sheridan - 12 May 2008 17:36 GMT
Duane's solution should work with your daily report, but if you are first
grouping the weekly report by days then the same OrderID could appear in more
than one group header if picked and loaded on separate days as this would be
the second group level, so it would again be counted twice.

A solution would be to count the distinct OrderID values in code in the
report's module.  First you'd declare two module level variables, one to hold
a value list of the distinct OrderIDs, one to hold the count.  In the detail
section's Print event procedure the OrderID would be added to the value list
and the count incremented each time a new OrderID is encountered.  Finally
the value of the count would be assigned to an unbound text box in the report
footer.  So the report's module would look something like this:

Option Compare Database
Option Explicit

Dim strIDList As String
Dim intIDCount As Integer

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

   If PrintCount = 1 Then
       If InStr(strIDList, "~" & Me.OrderID) = 0 Then
           strIDList = strIDList & "~" & Me.OrderID
           intIDCount = intIDCount + 1
       End If
   End If
   
End Sub

Private Sub ReportFooter_Print(Cancel As Integer, PrintCount As Integer)

   Me.txtOrderCount = intIDCount
   
End Sub

Note that I've used the tilde character as the delimiter for the value list
rather than the more usual comma, colon or semi-colon.  This is just in case
you are using a structured OrderID (or equivalent) which might contain one of
those characters.  I'm assuming it won't contain a tilde!  If it’s a simple
number such as an autonumber it will still work of course.

Ken Sheridan
Stafford, England

> I am new to Access.  I have a field OrderID, I need it to count the total #
> of orders for a daily report and a weekly report.  The problem is more than 1
[quoted text clipped - 6 lines]
> really would appreciate any help that someone can offer me.  Thanks in
> advance!
clueless - 27 May 2008 15:43 GMT
Ken,
Thanks for responding.  Please bear with me, my 2 one day Access Certificate
classes at the local college did not cover modules.  If I insert it in a
module, I get an error "Invalid use of Me keyword".  If I insert it in a
class module, I get "Method or data member not found" and .OrderID is
highlighted.  No idea what the difference is between the two and definitely
no idea how to correct the error.  What do I need to do?  Thanks for your
help!  
Signature

clueless

> Duane's solution should work with your daily report, but if you are first
> grouping the weekly report by days then the same OrderID could appear in more
[quoted text clipped - 51 lines]
> > really would appreciate any help that someone can offer me.  Thanks in
> > advance!
Duane Hookom - 27 May 2008 16:08 GMT
Ken's suggestion would place the code in the Report's module. You could
select the detail section of the report and find the On Print event. Click
the builder button [...] on the far right and choose to enter some code.
Signature

Duane Hookom
Microsoft Access MVP

> Ken,
> Thanks for responding.  Please bear with me, my 2 one day Access Certificate
[quoted text clipped - 60 lines]
> > > really would appreciate any help that someone can offer me.  Thanks in
> > > advance!
clueless - 27 May 2008 16:32 GMT
Duane,
Thanks for your help in clarifying how to do this.  I appreciate it!
Signature

clueless

> Ken's suggestion would place the code in the Report's module. You could
> select the detail section of the report and find the On Print event. Click
[quoted text clipped - 64 lines]
> > > > really would appreciate any help that someone can offer me.  Thanks in
> > > > advance!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.