I am using a datediff function to calculate the number of work days between two dates.
The problem is that when the form opens, I seem to have to have a value in the fields that are part of the datediff function, or else I get an error becuase the fields are null. I also experience this problem when people use my form, but have only some of the fields that are used in this function, blank. For example, they might put in the begdate and not the end date.
Question: Could anyone help me with a simple line of code that I could put at the beginning of my datediff module that will evaluate, if the fields are null(blank), then don't perfom the datediff function? Here is my code that I am using. I figure that way, if they don't enter the begdate and the endate, then I won't try to run the funtion.
Function DateDiffW(BegDate, EndDate)
Const SUNDAY = 1
Const SATURDAY = 7
Dim NumWeeks As Integer
If BegDate > EndDate Then
DateDiffW= 0
Else
Select Case Weekday(BegDate)
Case SUNDAY : BegDate = BegDate + 1
Case SATURDAY : BegDate = BegDate + 2
End Select
Select Case Weekday(EndDate)
Case SUNDAY : EndDate = EndDate - 2
Case SATURDAY : EndDate = EndDate - 1
End Select
NumWeeks = DateDiff("ww", BegDate, EndDate)
DateDiffW= NumWeeks * 5 + Weekday(EndDate) - Weekday(BegDate)
End If
End Function
The problem is that when the form opens, I seem to have to have a value in the fields that are part of the datediff function, or else I get an error becuase the fields are null. I also experience this problem when people use my form, but have only some of the fields that are used in this function, blank. For example, they might put in the begdate and not the end date.
Question: Could anyone help me with a simple line of code that I could put at the beginning of my datediff module that will evaluate, if the fields are null(blank), then don't perfom the datediff function? Here is my code that I am using. I figure that way, if they don't enter the begdate and the endate, then I won't try to run the funtion.
Function DateDiffW(BegDate, EndDate)
Const SUNDAY = 1
Const SATURDAY = 7
Dim NumWeeks As Integer
If BegDate > EndDate Then
DateDiffW= 0
Else
Select Case Weekday(BegDate)
Case SUNDAY : BegDate = BegDate + 1
Case SATURDAY : BegDate = BegDate + 2
End Select
Select Case Weekday(EndDate)
Case SUNDAY : EndDate = EndDate - 2
Case SATURDAY : EndDate = EndDate - 1
End Select
NumWeeks = DateDiff("ww", BegDate, EndDate)
DateDiffW= NumWeeks * 5 + Weekday(EndDate) - Weekday(BegDate)
End If
End Function