Solved

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

Posted on 2012-12-31
2
501 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
[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
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

734 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