I am running the below expression to compare the diffence of 2 dates. If both dates are in the cell I would like it to return a 0 but if Date2 is blank I would like the difference to show. Right now I just get #ERROR if there is no date in date2. Any ideas would be greatly appreciated.
expr2: NetWorkDays([Date1],[Date2])
Option Compare Database
Public Function NetWorkdays(dteStart As Date, dteEnd As Date) As Integer
Dim intGrossDays As Integer
Dim dteCurrDate As Date
Dim i As Integer
intGrossDays = DateDiff("d", dteStart, dteEnd)
NetWorkdays = 0
For i = 0 To intGrossDays
dteCurrDate = dteStart + i
If Weekday(dteCurrDate, vbMonday) < 6 Then
End If
Next i
End Function
The function will always return 0 if you don’t remove the
NetWorkdays = 0from the function, and you will continue you to get an error if you don’t wrap where you call the function in an if statement like this:txtResult being the textbox you want to display your results in.
You may want to look at this link http://msdn.microsoft.com/en-us/library/bb258196(v=office.12).aspx. It is a function designed for access to calculate the number of workdays between two dates.
Using this function you should get the results you want doing something like this: