Ignore weekends when looping
Posted on 2012-09-17
I have a form that posts events to a db. If an event runs from 26/1/20?? to 30/1/20?? four seperate events are recorded in the db (1 ea for 26,27,28 &29).
I need to add a procedure to ignore weekends.
ie. If an event starts on 21/9/2012 and runs for 3 days I want records created for the 21st, 24th & 25th thus ignoring the weekend.
I have seen plenty of examples for identifying workdays but nothing that I've been able to adapt to the current script.
This is the script that posts my consecutive records
Private Sub Command18_Click()
Dim rst As DAO.Recordset
Dim dtLeave As Date
Set rst = CurrentDb.OpenRecordset("tblLeaveEvent")
dtLeave = Me.LeaveStart
Do Until dtLeave = Me.LeaveFinish
rst!UserID = Me.UserID
rst!LeaveType = Me.LeaveType
rst!LeaveStart = dtLeave
rst!LeaveFinish = dtLeave + 1
dtLeave = dtLeave + 1
Set rst = Nothing
I expect that I will need to modify the above to accomodate the week days only requirement but I have no idea how.
Thanks for your assistance.