Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
SELECT DISTINCT
Mubeezi Micah 

15 years ago
Well Richard,

You really made me look fool when I watched lesson 5 of the SQL seminar. I couldn’t believe that I took such a long route to achieve exactly the same result. I will share with you and my fellow students the problem, the solution that I applied and what I should have done really….

The problem;
My customer is a manager of a TB program. He has 18 health posts that report to him. He is expected to visit/supervise each health post at least once in a quarter. In reality, he can visit a facility one or more times per quarter. However for one reason or another, some facilities may not be visited within a three months period. At the end of a quarter, the TB manager sends a report to his HQ about the number of health posts he visited…not how many times (so the total should not exceed the 18 health posts).

This is what I did;
*VisitQ is a parameter query and it stores the names of the health posts and the exact dates when the TB manager visited them. In one of the TextBoxes of the report, I inserted the following formula (in the ControlSource;

=IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Ruhaama H/C III' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Rugarama H/C III' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Kayonza H/C III' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Ngoma H/C III' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Ntungamo H/C III' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Kitondo H/C III' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Nyakyera H/C III' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Rukoni H/C III' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Bwongyera H/C III' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Rweikiniro H/C III' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Butare H/C III' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Kagamba H/C III' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Itojo Hospital' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Kitwe H/C IV' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Rubaare H/C IV' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Rwashamaire H/C IV' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Rushooka H/C II' "),0)=0,0,1)+IIf(Nz(DCount("VisitID","VisitQ","HealthPost='Universal Care Clinic' "),0)=0,0,1)

I now realise that this is what I should have done;

After building VisitQ (parameter query above), I would have just built another query as follows;

SELECT DISTINCT HealthPost FROM VisitQ

Then I would save this query as HealthPostVisitedQ

In my ControlSource of the report, I would then just had one short formula as
=Nz(DCount("HealthPost","HealthPostVisitedQ"),0)

And that is it!

MICAH


Reply from Richard Rost:

Wow. So simple. So elegant. Good catch!

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/22/2026 9:53:26 AM. PLT: 1s