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 
Query w2 two separate dates
Don Pfeifer 
     
2 years ago
This question is based on data from Korea.
I have 2 tables. One with the names of (20) presidents and acting presidents and the dates that they came into office and left office, with some dates overlapping. The other table has 1.3m awards issued over the last 75 years.
I want to do a query to find out the number of awards issued by each president or acting president.
There are numerous videos on date queries. But, a parameter query won't work because the dates are separate fields in a table. Any suggestions on how to accomplish this. Later I will be doing queries for the number of the different types of awards per president. It is basically the same search, just using additional fields.
Adam Schwanz  @Reply  
           
2 years ago
The overlapping dates is going to be an issue. Are you saying there are 2 acting presidents at one time? Or that non-active presidents give awards?

I don't think this is something you do in a query though to start with. Doing a calculation to determine which president gave which award over 1.3million records, every time you run the query, is going to be horridly slow. I would add a field to the award table for which president gave the award, and then use a recordset to set the values of that field, it would be a long running recordset but it's only a one-time kind of thing. Once you have that data in a table you can make a query to work with the data however you want.
Don Pfeifer OP  @Reply  
     
2 years ago
Korea has had a turbulent history.
One president was up on corruption charges and was not allowed to do her official duties until the investigation was over, so you had an acting president while there was still a president in office. When the president was convicted, the acting president continued in the presidential capacity. Officially, her presidency did not finish until the conviction. There was also a military dictatorship where the general holding the real power kept a president in office, until he fully officially took over.
One issue that I have is that the Award Table is a living/breathing entity that is officially updated every three months.
As far as the wait time, this is a hobby pursuit, I'm retired, so I have the time. I just don't know how to query a count with two separate date fields. Also I could run each active/acting president separately, which should cut down the wait time, and that is the result that I am really looking for.
Adam Schwanz  @Reply  
           
2 years ago
So what are you wanting to happen when you have an award given that has 2 acting presidents during that time range? Access won't be able to figure out who was in trouble or who gave the award, is there some other criteria available?
Don Pfeifer OP  @Reply  
     
2 years ago
What I am looking for is to count the number of awards per president. Even if the terms in office overlap, it really shouldn't matter. I just need to get the total count of awards between this date and this date.
Adam Schwanz  @Reply  
           
2 years ago
If President A served 1/1/2000 to 1/1/2004 and President B served 1/1/2003 to 1/1/2005

Award 1 was given on 6/6/2000
Award 2 was given on 6/6/2002
Award 3 was given on 6/6/2003
Award 4 was given on 6/6/2004

President A would have given 3 awards (1,2,3) and President B would have given 2 awards (3,4). Award 3 is given by two presidents in this case. Is that fine or how do you want to handle that? Once I'm sure I understand how you want to add up the numbers I can help you make something to do it.

Don Pfeifer OP  @Reply  
     
2 years ago
The same award given by two presidents is okay. President A with 3 awards and President B with two awards, totaling 5 awards when there are only 4, is not a problem. Once I know how to do the query, I can refine it sometime down the road to show how much overlap.
I appreciate you taking the time to help me.
Don
Kevin Yip  @Reply  
     
2 years ago
I would suggest you enter the overlapping periods as separate entries in your table.  For instance:

PresidentName                 StartedOffice  LeftOffice
Park Geun-hye                 2013-02-25     2016-12-08
Park Geun-hye/Hwang Kyo-ahn   2016-12-09     2017-03-10
Hwang Kyo-ahn                 2017-03-11     2017-05-09

One entry for President Park serving alone.  A separate entry for Park and Hwang serving together (when Park was being impeached).  Another entry for Hwang serving alone (after Park was convicted and removed from office).  That way you will get accurate counts, because there is no overlapping of the dates in your table.  That is the trick.  Even when there is overlapping in real life, you can get rid of the overlapping by treating the overlapped period as a separate entity.
Stacy Atchison  @Reply  
      
2 years ago
Just my two cents, if I may!!  To possibly provide improved accuracy while accounting for overlapping time periods and changes in official positions, I suggest the following 3 tables with appropriate relationships applied of course ;)!!

PresidentT (or "OfficeHolder"T)
PresidentID   PresidentName
1                  Le Myung-bak
2                  Park Geun-hye
3                  Hwang Kyo-ahn
4                  Moon Jae-in

TermT                
PresidentID     Postion               StartDate         EndDate          
1                    President            02/25/2008     02/24/2013
2                    President            02/25/2013     03/10/2017
3                    Acting President  12/09/2016     05/09/2017
4                    President            05/10/2017     05/09/2022

AwardsGivenT
AwardID     Award               DateGiven       Givenby (PresidentID)
1                Award Abc         06/06/2012       1    
2                Award Cde         06/06/2014       2
3                Award Efg          06/06/2016       2
4                Award Ghi          01/25/2017       3
5                Award Ijk           06/06/2017       4
Adam Schwanz  @Reply  
           
2 years ago
The easiest way to do it if it doesn't have to be perfectly exact, is to just count the number of awards given during each presidents time period. (Which would result in 5 awards when there are only 4 like my example).

You could do that with a query field, bring in your presidents table, and add another field like (This is still probably going to be slow)
AwardsGiven: DCOUNT("*","AwardsT","AwardGivenDate>=# & PresidentStartDate & "# and AwardGivenDate<=# & PresidentEndDate & "#")

Now if you want to know which award was given by which president, I would do that with a recordset, although it is going to be a LONG running recordset (like walk away and do your taxes long probably). But it lets you use the data instantly in the future, and if it's only one time every 3 months like you said, that's probably OK. You said you want the counts of awards given by each president, so I'm not sure if which awards were given by which presidents is something you care about.
Don Pfeifer OP  @Reply  
     
2 years ago
I appreciate your help on this. Got a little tied up today, so I will work on this tomorrow.
Thanks.
Don
Don Pfeifer OP  @Reply  
     
2 years ago
Sorry for being such a pest, but I am having issues with the coding.
I changed all the names, double-checked them and double checked the original syntax and entered it into a query.
Now I am getting a 'The expression you entered has invalid syntax You may have entered an operand without an operator'
AwardsGiven: DCOUNT("*","AwardsT","AwardGivenDate>=# & PresidentStartDate & "# and AwardGivenDate<=# & PresidentEndDate & "#")
The first # and AwardGivenDate<=# is not having a problem, but the error focuses/highlights on the 2nd # and AwardGivenDate<=#
Any idea what I am doing wrong?
Adam Schwanz  @Reply  
           
2 years ago
Your missing quotations on both of the first #, sorry I must have missed that too.

AwardsGiven: DCOUNT("*","AwardsT","AwardGivenDate>=#" & PresidentStartDate & "# and AwardGivenDate<=#" & PresidentEndDate & "#")
Don Pfeifer OP  @Reply  
     
2 years ago
Thank you. I was looking at examples on the net and I was leaning towards the quotation marks, but wasn't sure.
Again, Thank you.

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: 6/17/2026 10:46:42 AM. PLT: 0s