martinjward
Registered User.
- Local time
- Today, 04:27
- Joined
- Sep 28, 2007
- Messages
- 22
I am trying to write a subroutine (which resides in a module) to calculate the number of days, hours and minuites between to date times (I have searched forums and only found working days calculations , no working hours).
I am trying to discount bank hols and weekends and this is what I can up with....
but before I can even test that this is giving the correct result (which I doub - 1st attempt at any significnt VBA) I get a complie error.
At the line 'If Daycount("[HolidayDate]", "tbl_HolidayList", "[Holiday] = #" & tmpDate & "#") > 0 Then' I get the error 'Expected Array'
Help, please
And if you see anything else that needs fixing please do so.
Thanks in advance.
Martin
I am trying to discount bank hols and weekends and this is what I can up with....
Code:
Public Sub DayDifference(dtestartdate As Date, dteenddate As Date)
Dim tmpdate As Date
Dim daycount As Integer
Dim datediffs As Integer
Dim daycounts As Integer
Dim finals As Integer
Dim finaldays As Integer
Dim finalhours As Integer
Dim finalmins As Integer
'### Reset Variables ###
daycount = 0 'Reset daycount to Zero
'### End Reset Variables ###
'### Check if need to only calculate hours ###
'If StartDate and EndDate are the same calculate Hours only
If dtestartdate <> dteenddate Then
'Add one day onto start date
tmpdate = dtestartdate + 1
'if tmpdate is the same as the same as the end, only calculate hours
If tmpdate <> EndDate Then
'End ### Check if need to only calculate hours ###
Do While tmpdate <> dteenddate
'### Count Non-Working Days ###
'### Count Weekend days###
Select Case Weekday(dteTemp)
Case Is = 1, 7
daycount = daycount + 1
'Count Weekend
Case Else
'Do Nothing
End Select
'### Count Bankholidays ###
If daycount("[HolidayDate]", "tbl_BankHolidays", "[HolidayDate] = #" & tmpdate & "#") > 0 Then
daycount = daycount + 1
End If
tmpdate = tmpdate + 1
Loop 'Do While tmpdate <> dteEndDate
'### End Count Non-Working Days ###
End If 'tmpStartDate = EndDate Then
End If 'dteStartDate = dteEndDate Then
'Convert daycount to seconds
daycounts = daycount * 86400
'### Calculate difference between start and end date ###
datediffs = DateDiff("s", StartDate, EndDate)
'### End Calculate difference between start and end date ###
'### Subtract Non-Working Days ###
finals = datediffs - daycounts
'### End Subtract Non-Working Days ###
'### Format result ###
finaldays = finals / 86400
finalhours = (finals - (finaldays * 86400)) / 3600
finalmins = (finals - (finals * 1400)) / 60
'### End Format Result ###
End Sub
but before I can even test that this is giving the correct result (which I doub - 1st attempt at any significnt VBA) I get a complie error.
At the line 'If Daycount("[HolidayDate]", "tbl_HolidayList", "[Holiday] = #" & tmpDate & "#") > 0 Then' I get the error 'Expected Array'
Help, please
And if you see anything else that needs fixing please do so.
Thanks in advance.
Martin
Last edited: