DK8
05-21-2007, 09:35 AM
I have written a function to check for smalldatetime. The forms use dates returned from the system, using DATE. The user is prompted with a messagebox asking for the date, which is already filled in with the system date. If the user types in a different date, it checks for smalldatetime, but only once. Then I get an error converting data type varchar to smalldatetime. I want the user to be prompted continuously until they enter a proper date. I hope this makes sense, the code is below. If someone would take a look I would be very grateful. Thanks in advance.
code:
Public Function TestSmallDateTime(datValue)
Dim varRetVal As Variant
Dim datDefaultDate As Date
Dim datHighDate As Date
Dim datLowDate As Date
datLowDate = #1/1/1900#
datHighDate = #6/6/2079#
TestSmallDateTime = datValue
If datValue >= datLowDate And datValue <= datHighDate Then
TestSmallDateTime = datValue
Else
If datValue >= datHighDate Then
Do Until datValue >= datLowDate And datValue <= datHighDate
MsgBox "You entered an invalid date!! Must be less than " & DateAdd("y", 1, datHighDate), vbOKOnly, "Bad Date"
datValue = InputBox("Deduction Change Effective Date (mm/dd/yyyy)? ", "Deduction Change", Format$(DATE, "mm/dd/yyyy"))
Exit Do
Loop
End If
End If
End Function
code:
Public Function TestSmallDateTime(datValue)
Dim varRetVal As Variant
Dim datDefaultDate As Date
Dim datHighDate As Date
Dim datLowDate As Date
datLowDate = #1/1/1900#
datHighDate = #6/6/2079#
TestSmallDateTime = datValue
If datValue >= datLowDate And datValue <= datHighDate Then
TestSmallDateTime = datValue
Else
If datValue >= datHighDate Then
Do Until datValue >= datLowDate And datValue <= datHighDate
MsgBox "You entered an invalid date!! Must be less than " & DateAdd("y", 1, datHighDate), vbOKOnly, "Bad Date"
datValue = InputBox("Deduction Change Effective Date (mm/dd/yyyy)? ", "Deduction Change", Format$(DATE, "mm/dd/yyyy"))
Exit Do
Loop
End If
End If
End Function