Access 2007-2016
Access 2000-2003
Access Seminars
TechHelp Support
Tips & Tricks
Access Forum
Course Index
Topic Glossary
Insider Circle
 
Home   News   Tips   Glossary   Templates   Forums   Help   Logon   Order   Contact Us  
 
NEW: Microsoft Access Developer Level 8    dismiss
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   
 

Count Items in a Report

How to count items in a report, resetting counter for each group

Q: I'm a member of the Access Insider's Club. I want to number the lines in an Access report. For example, I want to group employees by department, sorted by last name, first name. Next to each employee I want a number which increments by one for each employee. E.g.:

   1 Brown, Joe
   2 Jones, Allison
   3 Smith, Sam

and so on for however many employees in that department. I want the numbering to start over for each department. If a department goes to more than one page, the numbering should NOT start over with the new page, only when the department changes. I can't think of a way to do this.  >Greg

A: Greg, since I always help my Access Insider's Club, I've put this together just for you. There are a couple of different ways you can do this, but here is a solution that doesn't involve any programming.

First, here's a simple table I'm going to use for this example. It's just a CustomerID, CustomerName, and GroupID which would represent your "department." Yes, I'm stuck on Customers, but you could easily use this for Employees.

Now, create a simple query based on this table, but we're going to add one field to it. We're going to add a calculated field called Num which is just set equal to the value of 1. You'll see why in a few minutes. Just type in this for the field:  Num: 1

When you run this query, you'll see that each customer has a 1 next to him. That's OK.

Now create a simple report based on this query. Here's what mine looks like:

When I run the report, nothing fancy happens:

Now, let's create Sorting & Grouping Levels to break these customers down by group (employees by dept, et al.)

In Access 2003 or earlier, you just click on the Sorting & Grouping Level button on the toolbar. Then set up a group for GroupID and turn on the header or footer if you want it. I cover this in detail in this tutorial.

In Access 2007 they've really moved things around a lot (I still don't like Access 2007). You have to click on the Group & Sort button.

Then click on "Add a Group."

Then pick the field - in this case GroupID.

That will add the Group Header for you.

I'll move the GroupID into the Header and bold it, just so it looks better.

This will give the report this look:

Now, what about the numbering you asked for? Well, here's what all those 1s are for. Open up the properties for that Num textbox and find the RunningSum property. Set it to "Over Group."

Now look what you get:

There you go. The RunningSum property adds up the values of all of these items and then resets that value for every new group. That's why I had you create that query value with the 1 in it. No programming required.

Of course, sorting your names and all that stuff is easy. I cover that in my tutorials - which I know you've watched.

Hope this helps!

 

 


By Richard Rost   Richard Rost on Facebook Richard Rost on Twitter Richard Rost on Google Plus Richard Rost on LinkedIn Email Richard Rost

Click here to sign up for more FREE tips

 

You may want to read these articles from the 599CD News:

 

Learn
 
Accessindex
Excelindex
Wordindex
Windowsindex
PowerPointindex
Photoshopindex
Visual Basicindex
ASPindex
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Free Upgrades
Insider Circle
Student Databases
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Articles
Search Our Site
Waiting List
Production Schedule
Collapse Menus
Help
 
Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services
About Us
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Gift CDs
Contact
 
Live Chat
General Info
Support Policy
Contact Form
Email Us
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

Google Plus    LinkedIn

Blog RSS Feed    YouTube Channel
Richard Rost Microsoft MVP