I have forgotten to mention,If validation does not meet any condition cursor
should go TextBox2 prmpt for correct entry.
I am using dd/mm/yy date format
OssieMac wrote:
Try the following. Let me know if not working as you want it to but let me
know what locale date format you are using.
Private Sub TextBox2_AfterUpdate()
Dim bolValid As Boolean
Dim dateValid As Date
On Error Resume Next
dateValid = DateValue(Me.TextBox2)
On Error GoTo 0
If dateValid 0 Then
bolValid = True
Else
bolValid = False
MsgBox "Invalid date format in TextBox2" _
& vbCrLf & "Must be d/m/y format"
Exit Sub
End If
If Year(dateValid) = Year(Date) Then
bolValid = True
Else
bolValid = False
MsgBox "Invalid Year in TextBox2" & _
vbCrLf & "Must be " & Year(Date)
Exit Sub
End If
If Month(dateValid) = Month(Date) Then
bolValid = True
Else
bolValid = False
MsgBox "Invalid Month in TextBox2" & _
vbCrLf & "Must be " & Month(Date)
Exit Sub
End If
If dateValid = DateValue(Me.TextBox1) Then
bolValid = True
Else
bolValid = False
MsgBox "Invalid date in TextBox2" & _
vbCrLf & "Must be = to TextBox1"
Exit Sub
Exit Sub
End If
'You should not need following code
'Only there for testing
If bolValid Then
MsgBox "Date in TextBox2 is valid"
End If
End Sub
--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200905/1