Solved

Compare Y/N Field to Separate Table

Posted on 2010-11-11
14
384 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 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2016 7 33
zero pad a access form field 2 14
Modal form 11 29
Filter a form 8 11
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

813 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