Clifford
Thanks for the additional information. I have changed the name of the field
from Date.
Here is what I think might work best....let me know if you agree.
I have created a form (frmCountry) and a subform (frmdate_subform) which are
linked together. I would like to use this form/subform combo for date entry
using the code you listed below.
frmCountry contains the following fields: CRID (PK), Region (Continent),
and Country (Country).
frmdate_subform contains the following fields: DateID (PK), From_Date,
To_Date, Location (Country), and CRID (FK),
I then have a command button at the bottom of the form, and have entered
your code 'On Click'. I believe that your code would tell me if the date
range I chose contains a holiday or weekend date, and then I could make sure
to exclude that date, correct?
Once this code has run and the From_Date and To_Date have been updated for
all the countries, I would then run an Update Query to concatenate the
From_Date and To_Date to make FromTo_Date within this same table looking for
Null values in the FromTo_Date field. I would then have the FromTo_Date and
Location (Country) data on the same table.
I could then use the FromTo_Date and Location as a Lookup fields in another
Date table, which would be entered by the User. The User would go through
and choose the Project, the Country, the Dates (which I would have linked as
an equi-join from Country to Dates using the Location to limit the dates
viewable by the user), and the Activities.
Hopefully this makes sense.
Also, I have some more questions concerning your code. I am getting the
following error:
Run-time error '2465':
Microsoft Office Access can't find the field "|" referred to in your
expression.
The part of the code it doesn't like is as follows:
varHolidayDescription = DLookup("tblHolidays", "Holiday_Description", _
"Country_Name = """ & [txtCountry_Name] & """ and " & _
"Holiday_Date = #" & dtToCheck & "#")
I suspect it is because my tblHolidays doesn't contain all the same fields
as is listed in the code. In looking at the code, I am not entirely sure
what txtCountry_Name is, or is doing.
For my tblHolidays, it contains the following fields:
HolID (PK), Holiday_Date, Country_Name, and Holiday_Description.
Thanks in advance for any advice/assistance you can offer. I sincerely
appreciate it.
Devon
Clifford Bass said:
Hi Devon,
One thing first before getting to a possible solution. You mention a
Dates table and a field named Date. I would suggest renaming those to be
more specific. Date is a reserved word (think Date() function), and its use
for something else can lead to unexpected results. So maybe rename it to
something like FromAndToDates. Do a search in Access's online help for
"reserved words" to get a list of other reserved words to avoid using as
object names.
If I understand, you want to check a date range someone enters into a
field on a form. Is the country also on the form? If so it becomes pretty
simple. Once you have the separate from and to dates you loop through them,
one day at a time, checking first to see if each is a week-end day (if
excluding week-end days) and if a holiday. To check if a holiday, you would
use the country field on the form along with the dates. Untested code,
assumes an added field in tblHolidays named "Holiday Description"; "txt..."
items are fields on your form:
Dim dtToCheck As Date
Dim varHolidayDescription As Variant
For dtToCheck = [txtFromDate] To [txtToDate]
If WeekDay(dtToCheck) >= 2 And WeekDay(dtToCheck) <= 6 Then
' A weekday - is it a holiday
varHolidayDescription = DLookup("tblHolidays",
"Holiday_Description", _
"Country_Name = """ & [txtCountry_Name] & """ and " & _
"Holiday_Date = #" & dtToCheck & "#")
If IsNull(varHolidayDescription) Then
' Not a holiday - count it
Else
' A holiday - do not count
MsgBox "Skipping " & varHolidayDescription & "."
End If
Else
' A week-end day - do not count
End If
Next dtToCheck
If the country is not on the form, you will have to get it from the
wherever it is that it is specified.
Hope that helps,
Clifford Bass
Devon said:
Clifford
Thanks for the assistance. I do need a little more help.
I have created tblHolidays as you stated.
I was thinking that I would need to create an If/Then statement when
entering the From and To Dates in the Dates table (Dates table is updated
after the Countries table). I would then create numerous If/Then/ElseIf
statements that would go through and look for the various dates by Country.
For example, one might be If [Country_Name] = 'United States', then...
My problem, is I am not sure what to put in the Then part of the statement.
The Holiday date could be in the From Date, To Date, or a date in between the
two dates. If the holiday date is during the time period (From, To, or in
between) then I want to exclude it from the time period. For example, in the
United States, Christmas is on Friday, December 25, 2009. If I were to go
into December and the From Date is #12/21/2009# and To Date is #12/25/2009#,
then my date range for that week would only be #12/21/2009# through
#12/24/2009#. It would also be nice to include a pop-up message that would
say something like 'During this time period, #12/25/2009# was not included as
it is a Holiday in the country you have chosen. To see what holiday, please
see the tblHoliday.
Thanks
Devon