- Private Sub Txt_Date_Validate(Cancel As Boolean)
- ' Variable de formatage de la date
- Dim BDC_Date As String
-
- ' Vérification si la date existante est déjà correcte
- If IsDate(Txt_Date.Text) Then
- ' La date saisie est correcte
- Else
- ' La date saisie n'est pas formatée
- If IsNumeric(Txt_Date.Text) Then
- ' La date est au format jjmmaa
- If Len(Txt_Date.Text) = 6 Then
- BDC_Date = Left(Txt_Date, 2) & "/" & Mid(Txt_Date, 3, 2) & "/20" & Right(Txt_Date, 2)
- End If
- ' La date est au format jjmmaaaa
- If Len(Txt_Date.Text) = 8 Then
- BDC_Date = Left(Txt_Date, 2) & "/" & Mid(Txt_Date, 3, 2) & "/" & Right(Txt_Date, 4)
- End If
- End If
- ' Vérification que la date formatée est correcte
- If IsDate(BDC_Date) Then
- Txt_Date.Text = BDC_Date
- Else
- ' Dans les cas ou la saisie n'est pas correcte
- MsgBox "La date est incorrecte : " & Txt_Date.Text
- Txt_Date.SetFocus
- End If
- End If
- End Sub
Private Sub Txt_Date_Validate(Cancel As Boolean)
' Variable de formatage de la date
Dim BDC_Date As String
' Vérification si la date existante est déjà correcte
If IsDate(Txt_Date.Text) Then
' La date saisie est correcte
Else
' La date saisie n'est pas formatée
If IsNumeric(Txt_Date.Text) Then
' La date est au format jjmmaa
If Len(Txt_Date.Text) = 6 Then
BDC_Date = Left(Txt_Date, 2) & "/" & Mid(Txt_Date, 3, 2) & "/20" & Right(Txt_Date, 2)
End If
' La date est au format jjmmaaaa
If Len(Txt_Date.Text) = 8 Then
BDC_Date = Left(Txt_Date, 2) & "/" & Mid(Txt_Date, 3, 2) & "/" & Right(Txt_Date, 4)
End If
End If
' Vérification que la date formatée est correcte
If IsDate(BDC_Date) Then
Txt_Date.Text = BDC_Date
Else
' Dans les cas ou la saisie n'est pas correcte
MsgBox "La date est incorrecte : " & Txt_Date.Text
Txt_Date.SetFocus
End If
End If
End Sub