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 / Reports / Printing / April 2008

Tip: Looking for answers? Try searching our database.

Counting total number of unique values in a report

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
joe raposo - 21 Apr 2008 16:16 GMT
Hi Everyone

Wonderining if you can help me with this issue. I have a database that I use
to record the quality of service my technical folks deliver to our customers.
Field managers travel with the techs to observe their activities on a typical
service call. Data is entered via a form that consists of a unique Employee
number,Travel Date and a list of 50 activities (fields) that I expect to see
and I rate them on. The ratining is "MR","RI" or "N/A".

I have created a field travel report that filters on the Employee number
field and travel date however I would like the report to count the number of
"MR" in all fields within that particular report for that particular travel
date.

I would appreciate any help you could provide.

Thanks
John Spencer - 21 Apr 2008 17:03 GMT
Because of your structure you have a problem that you may need to solve with a
VBA function.

Your table structure is wrong since you should have
 -- Activities - one record for each type of activity
 -- ActivityRatings - one record for each ServiceCall + ActivityType
 -- Employees
 -- ServiceCalls - ServiceCallID, EmployeeID, ServiceDate, CustomerID
That structure would make your analysis very easy.

With your current structure you probably need something like the following
UNTESTED function.
Assumptions:
--StrRating is a string,
--EmployeeNumber is a number field, and
--ServiceDate is a datetime field
--Only one record per employee per service date.  If more you will need to
loop through all the records returned.

Public Function fCountRating(strRating, EmployeeNumber, ServiceDate)
'StrRating = the value you want to count
'EmployeeNumber = the unique employee identifier
'ServiceDate = the Date you are interested in
Dim strSQL As String
Dim dbAny As DAO.Database
Dim rstAny As DAO.Recordset
Dim fldAny As DAO.Field
Dim lCount As Integer

'Build a string containing the activity fields
strSQL = "SELECT FieldA, FieldB FROM [YourTable] " & _
         " WHERE EmployeeNumber = " & EmployeeNumber & _
         " AND ServiceDate = " & Format(ServiceDate, "\#yyyy-mm-dd\#")
Set dbAny = CurrentDb()
Set rstAny = dbAny.OpenRecordset(strSQL)

'Loop through all the fields and count those with the specified rating.
If rstAny.RecordCount > 0 Then
   For Each fldAny In rstAny.Fields
      If fldAny = strRating Then
         lCount = lCount + 1
      End If
   Next fldAny

   fCountRating = lCount
Else
   fCountRating = Null
End If

End Function

John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County

> Hi Everyone
>
[quoted text clipped - 13 lines]
>
> Thanks
 
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.