Private Sub Text1_KeyPress(KeyAscii As Integer) If Len(Text1) < 6 Then If Len(Text1) Mod 2 = 0 Then ' conversion des minuscules en majuscules (au cas où) If KeyAscii >= 97 Or KeyAscii <= 122 Then KeyAscii = KeyAscii - 32 ' si c pas une lettre If KeyAscii < 41 Or KeyAscii > 90 Then KeyAscii = 0 MsgBox "Veuillez saisir une lettre" Text1.SetFocus End If Else ' si c pas un chiffre If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0 MsgBox "Veuillez saisir un chiffre" Text1.SetFocus End If End If Else KeyAscii = 0 MsgBox "Pas plus de 6 caractères" End If End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub Text1_LostFocus() If Not Text1.Text Like "?#?#?#" Then MsgBox "Format incorrect" End If End Sub