Calculating Working Days using Todays Date

thesuggs76

Board Regular
Joined
Nov 15, 2006
Messages
247
Hi All
I am trying to calculate the working days and I have it working when I'm using two set dates, however when I try to use todays date, Date() it doesn't work. I have included the VB code that I'm using. The result is 0. I have created a quere where I used Date() but named it Today.

Any help would be much appreciated
Thanks



Public Function FWaitingTime(Received_Date As Date, Today As Date) As Integer
On Error GoTo Err_FWaitingTime

Dim intCount As Integer
Dim rst As DAO.Recordset
Dim DB As DAO.Database

Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tblHolidays", dbOpenSnapshot)

Received_Date = Received_Date + 1
'To count Received_Date as the 1st day comment out the line above

intCount = 0

Do While Received_Date <= InitialContact_Date

rst.FindFirst "[HolidayDate] = DateValue('" & Received_Date & "')"
If Weekday(Received_Date) <> vbSunday And Weekday(Received_Date) <> vbSaturday Then
If rst.NoMatch Then intCount = intCount + 1
End If

Received_Date = Received_Date + 1

Loop

FWaitingTime = intCount

Exit_FWaitingTime:
Exit Function

Err_FWaitingTime:
Select Case Err

Case Else
MsgBox Err.Description
Resume Exit_FWaitingTime
End Select

End Function
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
1) what is the value of InitialContact_Date?
2) use debug.print Received_Date within DoWhile to prove that code works
3) use debug.print intCount to prove that this variable ever chnages from zero
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,521
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top