Limiter contenu textbox en fonction de contenu combobox

Bonjour.

Je voudrais limite la valeur du Textbox en fonction du texte du combobox1 mais il s'affiche un message d'erreur

Je voudrais de l'aide

Ci-joint le fichier.

Merci par avance.

Bonjour le forum

Bonjour Sawtappo

Essaie avec ceci :

Case 48 To 57
     If ComboBox3.Value = "Rédaction" And CDbl(TextBox1.Value & (KeyAscii - 48)) > 10 Then
        MsgBox "La note de " & ComboBox3.Value & " est sur 10 "
        KeyAscii = 0

     ElseIf ComboBox3 = "Dictée" And CDbl(TextBox1.Value & (KeyAscii - 48)) > 10 Then
        MsgBox "La note de " & ComboBox3.Value & " est sur 10 "
        KeyAscii = 0

     ElseIf ComboBox3 = "Présentation" And CDbl(TextBox1.Value & (KeyAscii - 48)) > 10 Then
        MsgBox "La note de " & ComboBox3.Value & " est sur 10 "
        KeyAscii = 0

     ElseIf ComboBox3 = "Dessin" And CDbl(TextBox1.Value & (KeyAscii - 48)) > 10 Then
        MsgBox "La note de " & ComboBox3.Value & " est sur 10 "
        KeyAscii = 0

     ElseIf ComboBox3 = "Lecture" And CDbl(TextBox1.Value & (KeyAscii - 48)) > 10 Then
        MsgBox "La note de " & ComboBox3.Value & " est sur 10 "
        KeyAscii = 0

     ElseIf ComboBox3 = "Récitation/Chant" And CDbl(TextBox1.Value & (KeyAscii - 48)) > 10 Then
        MsgBox "La note de " & ComboBox3.Value & " est sur 10 "
        KeyAscii = 0

     ElseIf ComboBox3 = "EPS" And CDbl(TextBox1.Value & (KeyAscii - 48)) > 10 Then
        MsgBox "La note de " & ComboBox3.Value & " est sur 10 "
        KeyAscii = 0

     ElseIf ComboBox3 = "Etude de texte" And CDbl(TextBox1.Value & (KeyAscii - 48)) > 20 Then
        MsgBox "La note de " & ComboBox3.Value & " est sur 20 "
        KeyAscii = 0

     ElseIf ComboBox3 = "Histoire-Géographie" And CDbl(TextBox1.Value & (KeyAscii - 48)) > 20 Then
        MsgBox "La note de " & ComboBox3.Value & " est sur 20 "
        KeyAscii = 0

     ElseIf ComboBox3 = "Sciences" And CDbl(TextBox1.Value & (KeyAscii - 48)) > 20 Then
        MsgBox "La note de " & ComboBox3.Value & " est sur 20 "
        KeyAscii = 0

     ElseIf ComboBox3 = "Opérations" And CDbl(TextBox1.Value & (KeyAscii - 48)) > 20 Then
        MsgBox "La note de " & ComboBox3.Value & " est sur 20 "
        KeyAscii = 0

     ElseIf ComboBox3 = "Problème" And CDbl(TextBox1.Value & (KeyAscii - 48)) > 20 Then
        MsgBox "La note de " & ComboBox3.Value & " est sur 20 "
        KeyAscii = 0
    End If

Et juste après le KeyAscii = 0 de chaque paragraphe :

        MsgBox "La note de " & ComboBox3.Value & " est sur 10 "
        KeyAscii = 0
        TextBox1.Value = ""   <== ceci pour effacer la valeur

Grandement merci. Ça marche bien

bonsoir

ca se résumerait a ceci

Private Sub UserForm_Initialize()
    Me.ComboBox3.List = Array("Rédaction", "Dictée", "Etude de texte", "Présentation", "Histoire-Géographie", "Sciences", "Opérations", "Problème", "Dessin", "Lecture", "Récitation/Chant", "EPS")
End Sub

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
   Dim Maxi
   With TextBox1
   Select Case KeyAscii
    Case 48 To 57
        Select Case ComboBox3.Value
        Case "Rédaction", "Dictée", "Présentation", "Dessin", "Lecture", "Récitation/Chant", "EPS": Maxi = 10
        Case "Etude de texte", "Histoire-Géographie", "Sciences", "Problème", "Opérations": Maxi = 20
        End Select
        If CDbl(TextBox1.Value & Chr(KeyAscii)) > Maxi Then
            MsgBox "La note de " & ComboBox3.Value & " est sur " & Maxi
            KeyAscii = 0
            TextBox1 = ""
        End If
    Case 44, 46: KeyAscii = 44: If InStr(.Value, ",") Then KeyAscii = 0
    End Select
End With
End Sub

patricktoulon

Une solution concise.

Merci bien

Rechercher des sujets similaires à "limiter contenu textbox fonction combobox"