In my form I have the user enter in the current date in Textbox1. My program is designed only to work in 2009 so I want to check to make sure the 1) the date is in 2009 and 2) textbox1 is not empty. If it is empty then it displays a message box with "Not a Valid Date. Please Enter Date as MM/DD/YYYY. Date has to be in 2009" - this doesn't work. Second, if the date is outside of 2009 it is to display a meeage box saying "Date has to be in 2009".
Here is my current code which is not working.
Code
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1 = vbNullString Then Exit Sub
If IsDate(TextBox1) Then
Else
MsgBox "Not a Valid Date. Please Enter Date as MM/DD/YYYY. Date has to be in 2009"
TextBox1 = Date
Cancel = True
End If
If TextBox1.Value < "01/01/2009" Then
MsgBox "Date has to be in 2009"
TextBox1 = Date
Cancel = True
End If
If TextBox1.Value > "12/31/2009" Then
MsgBox "Date has to be in 2009"
TextBox1 = Date
Cancel = True
End If
End Sub
Display More
Any help is greatly appreciated.
Guy