TextBox validation avec plusieurs options

Bonjour à tous,

Dans une textbox standard je souhaiterais avoir deux variables pour valider le formulaire:

- Il faut que ça commence soit par B soit par TM

J'ai donc deux options:

Private Sub TextBox_TM_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If TextBox_TM.Text Like "B*"

  Else

    MsgBox "LA VALEUR RENSEIGNÉE NE CORRESPOND PAS A UNE BOITE!", vbCritical, "ERREUR:"
    TextBox_TM.Value = ""
    Cancel = True

    End If
End Sub

ou

Private Sub TextBox_TM_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If InStr(1, TextBox_TM.Value, "TM", vbTextCompare) = 0 Then
    MsgBox "LA VALEUR RENSEIGNÉE NE CORRESPOND PAS A UNE TM!", vbCritical, "ERREUR:"
    TextBox_TM.Value = ""
    Cancel = True

  End If
End Sub

Mais je n'arrive pas à faire que

"si ça commence par B ou TM je peux valider, sinon erreur".

Merci pour votre aide.

Proposition de code pour le test

If left(TextBox_TM.Text,1)="B" or left(TextBox_TM.Text,2)="TM" then

==> macro de validation

Else

MsgBox "LA VALEUR RENSEIGNÉE NE CORRESPOND PAS A UNE BOITE!", vbCritical, "ERREUR:"

TextBox_TM.Value = ""

Cancel = True

End If

End Sub

A tester

FINDRH

Merci!

Cela fonctionne parfaitement bien. :)

Rechercher des sujets similaires à "textbox validation options"