Solved

Compare Y/N Field to Separate Table

Posted on 2010-11-11
14
390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
14 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34115314
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
ID: 34115487
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34115700
that is only eleven,, any way

post sample data from tblHolidays including the name of the fields


0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:rsburge
ID: 34115843
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34115854
ok, i'll be out for a while, can you upload a copy of your db..
0
 

Author Comment

by:rsburge
ID: 34116158
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
ID: 34116516
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
 

Author Comment

by:rsburge
ID: 34139085
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
ID: 34155079
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
ID: 34155451
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 333 total points
ID: 34155615
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
ID: 34155791
thank you capricorn1...  I will try this too.
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 333 total points
ID: 34158307

this one show details in the form/subform



DB-Q-26609108-Holidays.mdb
0
 

Author Comment

by:rsburge
ID: 34164561
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

707 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