Solved

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

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

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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.
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…

803 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