Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Sebastion Anderson   on Mar 01 In MS Office Category.

  
Question Answered By: Atid Boonliang   on Mar 01

I threw together this which seemed to work.


Private Sub txtDateReceived_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If ((Myform.txtDateReceived.Value) <> "") Then
If (Not IsDate(Myform.txtDateReceived.Value)) Then
MsgBox "NOt a proper date"
Myform.txtDateReceived.SetFocus
Cancel = True
Else
If (DateDiff("D", Myform.txtDateReceived.Value, Now) < 0) Then
MsgBox "Date may not be a future  date"
Myform.txtDateReceived.SetFocus
Cancel = True
ElseIf (DateDiff("D", Myform.txtDateReceived.Value, Now) > 100) Then
msg = "Date may not be more than 100 days in the past"
msg = msg & Chr(13) & Myform.txtDateReceived & " is "
msg = msg & DateDiff("D", Myform.txtDateReceived.Value, Now) & "
ago"
MsgBox msg
Myform.txtDateReceived.SetFocus
Cancel = True
Else
Cancel = False
End If
End If
Else
Cancel = False
End If
End Sub

Share: 

 

This Question has 5 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on User Form Date Validation Or get search suggestion and latest updates.


Tagged: