我在我的VBA代碼中爲文本框設置了特定的日期格式。日期驗證:在文本框中設置最小和最大日期
這是我的代碼來驗證日期是正確的格式:
Function CheckDate(DateStg As String) As Boolean
If DateStg = "" Then
' Accept an empty value in case user has accidentally moved to a new row
CheckDate = True
lblMessage.Caption = ""
Exit Function
End If
If IsDate(DateStg) Then
CheckDate = True
lblMessage.Caption = ""
Else
CheckDate = False
lblMessage.Caption = "Sorry I am unable to recognise " & DateStg & " as a date."
End If
End Function
除了檢查,如果在文本框中的日期是實際的日期,我需要驗證文本框中日期不小於當前日期減1個月,和。另外,我想驗證日期不超過當前日期加1年。
所以:
- DateStg>今天 - 1個月
- DateStg <今天+1年
感謝您的幫助提前。