Solved

VBA - Calculating a date that is a weekday and not a holiday

Posted on 2012-12-31
2
460 Views
Last Modified: 2012-12-31
Hi Guys and Gals

I'm looking to create a custom function that I pass a date to and an integer. I want to add x days onto a date and the result date is not to be a holiday or a weekend. I've got so far myself but for some reason my function lookup is returning a 'false' when its testing if its a holiday, but only on some entries.

The holidays table is a simple 3 column table with ID, Description and Holiday (This is a date/time field).

In my test, I put Xmas day in as the start date and put holidays in for xmas, boxing day, and 1st - 4th Jan. Yet my output date comes back as 4th Jan which is a holiday.... I can't figure out why it won't recognise this is a holiday.

Attached is the database - what am I missing?

James
Trackers-VBA.accdb
0
Comment
Question by:Delerium1978
2 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 38732941
I don't know where you are located but for non-US operation you must use...

nHolidays = DCount(Expr:="[Holiday]", Domain:="[Holidays]", Criteria:="[Holiday] =#" & Format(InputDate, "yyyy-mm-dd") & "#")

 ...to get a a valid date in the holidays function.
0
 

Author Closing Comment

by:Delerium1978
ID: 38733064
Hi Peter,

I'm from the UK. Used that format line code and worked a charm. I had a hunch it was something format related but there's no clear documentation that states that you need to do this anywhere (that I found anyway).

Nice work anyway. Thanks :)

James
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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 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…

758 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

20 Experts available now in Live!

Get 1:1 Help Now