Private Sub TextBox7_change()
On Error Resume Next
X = Len(TextBox7)
Y = LTrim(TextBox7.Text)
D = TextBox7
If D = "" Then
Exit Sub
End If
If Left(D, 2) > 31 Then
MsgBox "GIORNO ERRATO", vbCritical, "DATA"
TextBox7.SelStart = 0
TextBox7.SelLength = Len(TextBox7)
TextBox7.SetFocus
Exit Sub
End If
If X = 2 Then TextBox7 = Y & "/"
If X = 4 Then Exit Sub
If Mid(D, 4, 2) = "" Then Exit Sub
If Mid(D, 4, 2) > 12 Then
MsgBox "MESE ERRATO", vbCritical, "DATA"
TextBox7.SelStart = 3
TextBox7.SelLength = Len(TextBox7)
TextBox7.SetFocus
Exit Sub
End If
e = Left(D, 2)
f = Mid(D, 4, 2)
Select Case f
Case "02"
If e > 29 Then GoTo Mess
Case "04", "06", "09", "11"
If e > 30 Then GoTo Mess
End Select
If X = 5 Then
TextBox7 = Y & "/"
Exit Sub
End If
If X = 6 Then Exit Sub
If X = 7 Then Exit Sub
If X = 8 Then Exit Sub
If X = 9 Then Exit Sub
G = Mid(D, 7, 4)
If G <= 2000 Or G >= 2101 Then
MsgBox "L'anno deve essere tra il 2000 ed il 2100", vbCritical, "DATA"
TextBox7.SelStart = 6
TextBox7.SelLength = Len(TextBox7)
TextBox7.SetFocus
Exit Sub
End If
If IsDate(TextBox7) = False Then
MsgBox "La data non è valida - Controllare mese, giorno e anno", vbCritical, "DATA"
TextBox7.SelStart = 0
TextBox7.SelLength = Len(TextBox7)
TextBox7.SetFocus
Exit Sub
End If
If X = 10 Then
Exit Sub
End If
Exit Sub
Mess:
MsgBox "GIORNO ERRATO", vbCritical, "DATA"
TextBox7.SelStart = 0
TextBox7.SelLength = Len(TextBox7)
TextBox7.SetFocus
Set X = Nothing
Set Y = Nothing
Set D = Nothing
Set e = Nothing
Set f = Nothing
Set G = Nothing
Resume
End Sub |