I wrote a small function to test date/time and I'm told since I put the code in that users are becoming stuck in an endless loop. I have tested the function myself many times over and haven't encountered any problems. Can someone spot something which I may have overlooked? Thanks in advance.
Code is as follows:
Public Function TestSmallDateTime(datValue)
Dim varRetVal As Variant
Dim datTestSmallDateTime As Date
Dim datDefaultDate As Date
Dim blnContinue As Boolean
Dim datHighDate As Date
Dim datLowDate As Date
datLowDate = #1/1/1900#
datHighDate = #6/6/2079#
Do Until TestSmallDateTime = datValue
If (IsDate(datValue)) Then
If datValue >= datLowDate And datValue <= datHighDate Then
blnContinue = True
TestSmallDateTime = datValue
Else
blnContinue = False
MsgBox "You entered an invalid date!! Must be less than " & DateAdd("y", 1, datHighDate), vbOKOnly, "Bad Date"
End If
Exit Do
Else
blnContinue = False
MsgBox "You entered an invalid date!! Must be less than " & DateAdd("y", 1, datHighDate), vbOKOnly, "Bad Date"
End If
Exit Do
Loop
End Function
Code is as follows:
Public Function TestSmallDateTime(datValue)
Dim varRetVal As Variant
Dim datTestSmallDateTime As Date
Dim datDefaultDate As Date
Dim blnContinue As Boolean
Dim datHighDate As Date
Dim datLowDate As Date
datLowDate = #1/1/1900#
datHighDate = #6/6/2079#
Do Until TestSmallDateTime = datValue
If (IsDate(datValue)) Then
If datValue >= datLowDate And datValue <= datHighDate Then
blnContinue = True
TestSmallDateTime = datValue
Else
blnContinue = False
MsgBox "You entered an invalid date!! Must be less than " & DateAdd("y", 1, datHighDate), vbOKOnly, "Bad Date"
End If
Exit Do
Else
blnContinue = False
MsgBox "You entered an invalid date!! Must be less than " & DateAdd("y", 1, datHighDate), vbOKOnly, "Bad Date"
End If
Exit Do
Loop
End Function