[VBA] - Probleme de caractères

Résolu
Bonjour,

J'ai un bout de code qui fonctionne, mais pas comme je veux, le probleme se situe ligne 1 dans ma condition
comment dire que si ma textbox comporte que 5 caractère alors on continue,parce que dans le code ci-dessous si j'en ai + de 5 alors on continue, moi j'en veux que 5, pas 4 ni 6, mais 5

1 - If TextBoxReferenceProduit.Value = Left(TextBoxReferenceProduit.Value, 5) Then
2 - .Value = "'" & Left(LTrim(UserForm2.TextBoxReferenceProduit.Value), 5) + UserForm2.TextBoxVersion.Value +
3- UserForm2.TextBoxIndice.Value + UserForm2.TextBoxSup.Value 'Gestion du zéro
4 - End If

Quelqu'un aurait une idée s'il vous plait

Merci

Jeyjey1
Configuration: Windows XP
Internet Explorer 6.0

5 réponses

  1. Tu peux tester la longueur du champ avec le OnKeyPress.

    If Len(Me.TextBoxReferenceProduit) >= 5 Then ' éviter Copy/Paste
    InputCharacter = Chr(0)
    End If

    Puis encore pour gérer Copy/Paste

    OnExit
    Me.TextBoxReferenceProduit = Left(Me.TextBoxReferenceProduit, 5)
    0
    1. Merci Phil232 pour ton aide précieuse
      Ci joint mon code final avec la soluce de Phil232

      If Len(TextBoxReferenceProduit.Value) = 7 Then
      .Value = "'" & Left(LTrim(UserForm2.TextBoxReferenceProduit.Value), 5) + UserForm2.TextBoxVersion.Value + UserForm2.TextBoxIndice.Value + UserForm2.TextBoxSup.Value 'Gestion du zéro
      Else
      .Value = "'" & Left(LTrim(UserForm2.TextBoxReferenceProduit.Value), 10) + UserForm2.TextBoxVersion.Value + UserForm2.TextBoxIndice.Value + UserForm2.TextBoxSup.Value 'Gestion du zéro

      End If

      Merci encore
      0
      1. Oups,

        tu es sure que ça fonctionnera comme voulu ? On doit donc tapper 7 fois pour récuperer 5 caractères ? Sinon, même s'il n'y a qu'un caractère tu fait un Left(xxx, 10) avec ?
        0
        1. Enfait si ma textbox comporte 7 caracteres, les 5 premiers caracteres sont copiés dans une cellule voisine et ensuite je refais la meme chose sauf que la je copie les 10 premiers caracteres
          0