Solved

Compare Y/N Field to Separate Table

Posted on 2010-11-11
14
383 Views
Last Modified: 2012-05-10
I have searched but haven't been able to find a solution for this problem.

In an Access 2007 database I have inherited, there is a table, tblLenders, that includes various information on lenders and includes 12 Y/N fields, one for each federal holiday in the year.

There is also a table, tblHolidays, which lists a hoiday name and date for each federal holiday in the year.

I need to figure out how to exclude a record from a query of tblLenders if all of the criteria below are met...
1. Today's Date is present in tblHolidays
2.  The Holiday Name in tblLenders is "Y"

Ultimately, I am trying to obtain a list of lenders that are not closed on today's date.  Because of the way this data is stored, I can't figure this out.

For example...  if today's date (11/11/2010) is in the values in tblHolidays.Hdt, that would be VeteransDay (tblHolidays.Hnm); and tblLenders.VeteransDay = "Y" then this record should be excluded from the query.
0
Comment
Question by:rsburge
  • 7
  • 5
  • 2
14 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
first create a Union query using tbllenders

select Id,lendername, [nameof first Y/N field] as Holiday from tblLenders
union All
select Id,lendername, [nameof second Y/N field] as Holiday from tblLenders
union all
select ....


union all
select Id,lendername, [nameof 12 Y/N field] as Holiday from tblLenders


after you have done this, post back here and we will continue

* use the appropriate names of fields in the union query






0
 

Author Comment

by:rsburge
Comment Utility
Ok, this is done...  this is the query I created qryUnionLndrHol

SELECT tblLenders.ID, tblLenders.LenderName, tblLenders.[NewYearsDay] AS holiday FROM tblLenders;
union all
SELECT tblLenders.ID, tblLenders.LenderName, tblLenders.[MLKJrDay] AS holiday FROM tblLenders;
union all
SELECT tblLenders.ID, tblLenders.LenderName, tblLenders.[WashingtonBday] AS holiday FROM tblLenders;
union all
SELECT tblLenders.ID, tblLenders.LenderName, tblLenders.[MemorialDay] AS holiday FROM tblLenders;
union all
SELECT tblLenders.ID, tblLenders.LenderName, tblLenders.[IndependenceDay] AS holiday FROM tblLenders;
union all
SELECT tblLenders.ID, tblLenders.LenderName, tblLenders.[LaborDay] AS holiday FROM tblLenders;
union all
SELECT tblLenders.ID, tblLenders.LenderName, tblLenders.[ColumbusDay] AS holiday FROM tblLenders;
union all
SELECT tblLenders.ID, tblLenders.LenderName, tblLenders.[VeteransDay] AS holiday FROM tblLenders;
union all
SELECT tblLenders.ID, tblLenders.LenderName, tblLenders.[ThanksGivingDay] AS holiday FROM tblLenders;
union all
SELECT tblLenders.ID, tblLenders.LenderName, tblLenders.[DayAfterThnxgvng] AS holiday FROM tblLenders;
union all
SELECT tblLenders.ID, tblLenders.LenderName, tblLenders.[ChristmasDay] AS holiday FROM tblLenders;
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
that is only eleven,, any way

post sample data from tblHolidays including the name of the fields


0
 

Author Comment

by:rsburge
Comment Utility
I apologize, it is only 11 holidays.

HolidayID - automated number and key field
HolidayNm - Name of Holiday (11 holiday names matching those in the query above)
HolidayDt - Short Date format

HolidayID     HolidayNm                HolidayDt
          1        NewYearsDay         1/1/2010
          2        MLKJrDay                 1/18/2010
and so on...
        11        ChristmasDay          12/24/2010

the HolidayDt field will be updated each year with the current year's dates.
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
ok, i'll be out for a while, can you upload a copy of your db..
0
 

Author Comment

by:rsburge
Comment Utility
unfortunately I can't upload a copy of the database; lots of confidential information in the tables.  No worries on your being out.  I am not in a huge hurry; I have two weeks before the next holiday.  :)  And I really appreciate your offering your assistance.
0
 
LVL 18

Expert Comment

by:lludden
Comment Utility
SELECT tblLenders.ID, tblLenders.LenderName, tblHoliday.HolidayDt
FROM tblLenders, tblHoliday
WHERE (((tblLenders.NewYearsDay)=True) AND ((tblHoliday.HolidayNm)="New Years Day"))
UNION
SELECT tblLenders.ID, tblLenders.LenderName, tblHoliday.HolidayDt
FROM tblLenders, tblHoliday
WHERE (((tblLenders.Christmas)=True) AND ((tblHoliday.HolidayNm)="Christmas"))


This will give you a list of each customer and each holiday they are closed and the date of the holiday
(repeat the query for each holiday)

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:rsburge
Comment Utility
I am not sure how to use this solution...  My end goal is to have one complete list of the records from tblLenders that are open "today".

This list that I am trying to obtain will be the filter on a form.
0
 
LVL 18

Assisted Solution

by:lludden
lludden earned 167 total points
Comment Utility
The query I gave you will return a list of all dates that each lender is closed.  If they are open any days they are not closed, then you can call the above query qryLenderClosedDates and do

SELECT LenderID, LenderName FROM tblLenders WHERE ID NOT IN (SELECT ID FROM qryLenderClosedDates WHERE HolidayDt = date())

This will show a list of all clients that are open on the current date, assuming they are only closed on the holidays.  You will need to exclude other days such as weekends.
0
 

Author Comment

by:rsburge
Comment Utility
Thank you for explaining that.  Let me give that a try.  I will post back as soon as possible.  Busy morning here, so it might be a few hours.
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 333 total points
Comment Utility
sorry, i lost track of this thread, don't know why..anyway

test this sample db,
run query2
DB-Q-26609108-Holidays.mdb
0
 

Author Comment

by:rsburge
Comment Utility
thank you capricorn1...  I will try this too.
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 333 total points
Comment Utility

this one show details in the form/subform



DB-Q-26609108-Holidays.mdb
0
 

Author Comment

by:rsburge
Comment Utility
I'm sorry I haven't had time to test these yet...  servers at the co-location have been up and down because of a DOS attack against the firewall.  I won't be able to test these until that is fixed.  I will get back to you as soon as I can.  Thanks again for your help!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now