1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
Sub testDateNaissance()
On Error GoTo ErrAgent
Dim maDate As Variant 'Cette ligne est inutile si vous remplacez "maDate" par TextBox11 dans ce qui suit :
Dim inputOK As Boolean: inputOK = False
Do While inputOK = False
'InputBox est inutile si vous remplacez "maDate" par TextBox11
maDate = InputBox("Introduisez la date de naissance (format 'jj/mm/aaaa'):", "Date", Int(Now()), 1)
If maDate = "" _
Or Val(maDate) = 0 _
Or Len(maDate) < 10 Then
MsgBox "Date incorrecte !", vbCritical + vbOKOnly, "Erreur date"
ElseIf DateDiff("yyyy", DateSerial(Year(maDate), Month(maDate), Day(maDate)), Now()) < 18 Then
MsgBox "Age inférieur à 18 ans !", vbCritical + vbOKOnly, "Erreur date"
Else
inputOK = True
End If
Loop
maDate = Format(maDate, "yyyy/mm/dd")
MsgBox "Le date introduite est : " & Format(maDate, "dd/mm/yyyy")
ErrAgent_Exit:
Exit Sub
ErrAgent:
MsgBox "Le format de la date de naissance est incorrect !", vbCritical + vbOKOnly, "Erreur date"
Me.TextBox11 = "": Me.TextBox11.SetFocus
Resume ErrAgent_Exit
End Sub |
Partager