XL 2010 ComboBox.ListIndex en panne

jeanba

XLDnaute Occasionnel
Bonjour le fil,

Mon formulaire est sensé:
- se remplir avec des données se trouvant sur un journal courant
- porter les modif souhaitées par l'user
- enregistrer TOUTES les modif apportées
- enregistrer le classeur ouvert

Je crois que mon code est bon, mais , je ne comprends pas pourquoi TOUTES les instructions ne s'exécutent pas. un oeil neuf s'il vous plaît?

Merci par avance
Jeanba
 

Pièces jointes

  • ComboBox_Change Jeanba.xlsm
    40.1 KB · Affichages: 31

Bebere

XLDnaute Barbatruc
bonjour jeanba,pierrejean
effectivement il manque un module
tci est dimensionné mais vide,il faut l'initialiser
Dim TCI(6) As String '2 To 8
For i = LBound(TCI) To UBound(TCI)'0 à 6
TCI(i) = i + 2
Next i

pour comparer
For i = LBound(TCI) To UBound(TCI)
If Me.ComboBox2.Value = TCI(i) Then TEST = True: Exit For
Next
déclare i as long(lire aide touche F1)
explique un peu mieux ce que tu veux
 

Bebere

XLDnaute Barbatruc
jeanba
fait quelques changements dans le code,tu compares avec ton code
mis en commentaire ce qui était avant
déplacer la variable test en début de code
ps:tu as eu 2 réponses de personnes différentes
 

Pièces jointes

  • ComboBox_Change JeanbaV1.xlsm
    42.3 KB · Affichages: 31

jeanba

XLDnaute Occasionnel
Bonjour Bebere,

Je viens de lire ton post.
C'est cool pour certaines de mes questions, notamment la prise en compte des modif sur le compte Tiers.
En revanche, les instructions suivantes ne semblent pas être suivies:

1°) Me.ComboBox3.Enabled = False lorsque la valeur du ComboBox2 (code imput) est égale à "02-08" ou "42"
Code:
If Me.ComboBox2 Like "01" _
And Me.ComboBox2 Like "09" _
And Me.ComboBox2 Like "[10-41]" _
And Me.ComboBox2 Like "[43-50]" Then
    Me.ComboBox3.Enabled = False


2°) J'ai trouvé la solution pour CONCATENER la date et texte dans TextBox
En fait, je rends invisbles les TextBox à concatener et je récupère leurs valeurs respectives dans le TextBox destinataire;Code
Code:
   Me.TextBox7 = "Vous modifiez la Pièce de Caisse n° " _
    + Me.ComboBox1 _
    + " saisie le " _
    + Me.TextBox8.Value _
    + " par " + Me.TextBox9.Value
 

Bebere

XLDnaute Barbatruc
jeanba
Application.ScreenUpdating = False une fois dans UserForm_Initialize suffit
remettre à true si terminé
pour concaténer le caractère & à la place de +
comme suit si bien compris
Code:
Private Sub ComboBox2_Change()

' Filtre sélectif de la liste des Tiers par catégorie (Clients ou Fournisseurs)
' ******************************************************************************
Dim i As Byte
Dim CEL As Range

Me.ComboBox2.Value = Format(Me.ComboBox2.Value, "00")

If Me.ComboBox2 <> "" Then
    Me.TextBox4.Visible = True
    With Feuil3
        Me.TextBox4 = .Cells(Me.ComboBox2.ListIndex + 2, 2)
    End With
End If

TEST = False
Me.ComboBox3.Clear
For i = LBound(TCI) To UBound(TCI)
    If Me.ComboBox2.Value = TCI(i) Then TEST = True: Exit For
Next
If TEST = True And Me.ComboBox2.Value <> "42" Then TEST = True
If TEST = False Then
    Me.ComboBox3.Enabled = False
End If

If Me.ComboBox2 Like "0[2-8]" Then
    For Each CEL In Feuil2.[planTiers_NumTiers]
        If Left(CEL.Value, 1) = "0" Then Me.ComboBox3.AddItem CEL.Value
    Next CEL
End If
If Me.ComboBox2.Value = 42 Then
    TEST = True
    For Each CEL In Feuil2.[planTiers_NumTiers]
        If Left(CEL.Value, 1) = "F" Then Me.ComboBox3.AddItem CEL.Value
    Next CEL
    Me.ComboBox3.Enabled = True
End If
'Me.ComboBox3.Enabled = TEST

End Sub
 

ChTi160

XLDnaute Barbatruc
Bonsoir jeanba
Bonsoir le fil,Le Forum
juste histoire de vous saluer Lol
cette phrase , veut dire qu'il faut que toutes les Conditions soient remplies "And"
si on remplace le "And " par "Or" ça devrait fonctionner !
VB:
 If Me.ComboBox2 Like "01" _
And Me.ComboBox2 Like "09" _
And Me.ComboBox2 Like "[10-41]" _
And Me.ComboBox2 Like "[43-50]" Then
    Me.ComboBox3.Enabled = False
Bonne continuation ;
Amicalement
Jean marie
 

jeanba

XLDnaute Occasionnel
Bebere,

Ton code marche super bien.
Cependant, il se passe que lorsque le formulaire est ouvert, que tu rentre dedans une valeur différente de 02 à 08 et 42, le combobox3 se désactive effectivement. Mais, si tu reviens dessus en sélectionnant une valeur de 02 à 08, il reste toujours désactivé, sauf pour 42 où à tous les coups il réagit bien.

Alors, je me demande s'il n'y a pas une incidence du "0" quelque part...
 

Bebere

XLDnaute Barbatruc
lis bien le code par rapport au précédent
bonjour à Jean Marie

Code:
Private Sub ComboBox2_Change()

' Filtre sélectif de la liste des Tiers par catégorie (Clients ou Fournisseurs)
' ******************************************************************************
'    Application.ScreenUpdating = False    'déjà dans initialise
    Dim i As Byte
    Dim CEL As Range


    If Me.ComboBox2 <> "" Then
        Me.ComboBox2.Value = Format(Me.ComboBox2.Value, "00")
        Me.TextBox4.Visible = True
        With Feuil3
            Me.TextBox4 = .Cells(Me.ComboBox2.ListIndex + 2, 2)
        End With

        TEST = False
        Me.ComboBox3.Clear
        For i = LBound(TCI) To UBound(TCI)
            If Me.ComboBox2.Value = TCI(i) Then TEST = True: Exit For
        Next
        If TEST = True And Me.ComboBox2.Value <> 42 Then TEST = True
        If TEST = False Then
            Me.ComboBox3.Enabled = False
        Else
            Me.ComboBox3.Enabled = True
        End If

        If Me.ComboBox2 Like "0[2-8]" Then
            For Each CEL In Feuil2.[planTiers_NumTiers]
                If Left(CEL.Value, 1) = "0" Then Me.ComboBox3.AddItem CEL.Value
            Next CEL
        End If
        If Me.ComboBox2.Value = 42 Then
            TEST = True
            For Each CEL In Feuil2.[planTiers_NumTiers]
                If Left(CEL.Value, 1) = "F" Then Me.ComboBox3.AddItem CEL.Value
            Next CEL
            Me.ComboBox3.Enabled = True
        End If

    End If

    'Me.ComboBox3.Enabled = TEST

End Sub

' Affiche pour vérification de la Raison sociale du Tiers concerné
' -------------------------------------------------------------------------------------
Private Sub ComboBox3_Change()
    If Me.ComboBox3 <> "" Then
        Me.TextBox5.Visible = True
        With Feuil2
            Me.TextBox5 = .Cells(Me.ComboBox3.ListIndex + 2, 1)
        End With
    End If
End Sub
 

jeanba

XLDnaute Occasionnel
Heuuu!
Sais pas ce qui s'est passé, mais tout marche bien à présent!
Il reste un souci, je crois lié au fait que Bebere dans ton code, t'as déclaré TCI(6) et non TCI(2 to 8)

le problème est que ce code ne contrôle plus la saisie ou non du tiers client lorsque la valeur du Code d'imputation (ComboBox2) = 02 à 08

Code:
For i = LBound(TCI) To UBound(TCI) '2 To 8
If Me.ComboBox2.Value = TCI(i) Then TEST = True: Exit For
    If TEST And Me.ComboBox3.Value = "" Then 'Me.ComboBox2.Value = TCI(i)
        MsgBox "Vous devez renseigner le Compte tiers Client!"
        Me.ComboBox1.SetFocus
        Exit Sub
    End If
Next i
 

jeanba

XLDnaute Occasionnel
Dans le fichier joint en tout cas, ce test n'est pas vérifié!!
En dehors de ce dernier détail, le reste des problèmes semble maintenant résolu

Merci encore
 

Pièces jointes

  • ComboBox_Change JeanbaV1.xlsm
    43.9 KB · Affichages: 35

ChTi160

XLDnaute Barbatruc
Re
pas sur d'avoir compris , mais j'ai mis cela ????
VB:
If Me.ComboBox2 Like "0[2-8]" Then
    For Each CEL In Feuil2.[planTiers_NumTiers]
        If Left(CEL.Value, 1) = "0" Then Me.ComboBox3.AddItem CEL.Value
    Next CEL
    Me.ComboBox3.Enabled = True
End If
Amicalement
Jean marie
 

Discussions similaires

Statistiques des forums

Discussions
311 737
Messages
2 082 036
Membres
101 878
dernier inscrit
1475214