Réinitialiser combobox et problème modification bd

Bonjour à tous

quand je lance userform que je clique sur la combobox1 Me trouve bien la liste des clients sans doublon ça alimente bien la 2e combobox en me mettant les bon N°facture du client

Le problème c'est que si je re sélectionne un autre client dans la combobox1 dans la 2 il y a toutes les factures qui apparaissent je suis donc obligé de refermer userform Et de le relancer

2e problème c'est quand je remplis la combobox3 et la textbos5 Et que je valide ça ne modifie pas la facture existante Ça me rajoute une ligne supplémentaire

Merci d'avance pour votre aide

Option Explicit

Dim fbd, derLn, ln, dico1, dico2

Private Sub ComboBox1_Change()
    ComboBox2.Clear
    TextBox1 = ""
    TextBox2 = ""
    TextBox3 = ""
     TextBox4 = ""
    For ln = 2 To fbd.Range("A" & derLn).Row
        If fbd.Range("C" & ln) = ComboBox1 Then
            dico2(fbd.Range("A" & ln).Value) = ""
        End If
    Next ln
    ComboBox2.List = Application.Transpose(dico2.keys)
End Sub

Private Sub ComboBox2_Change()

    TextBox1 = ""
    TextBox2 = ""
    TextBox3 = ""
    TextBox4 = ""
    For ln = 2 To fbd.Range("A" & derLn).Row
        If fbd.Range("C" & ln) = ComboBox1 And fbd.Range("A" & ln) = ComboBox2 Then
            TextBox1 = fbd.Range("K" & ln)
            TextBox2 = fbd.Range("BN" & ln)
            TextBox3 = fbd.Range("CP" & ln)
            TextBox4 = fbd.Range("N" & ln)
        End If
    Next ln

End Sub

Private Sub CommandButton1_Click()
    fbd.Range("N" & ln) = ComboBox3
    fbd.Range("CP" & ln) = TextBox5
    Unload Me
End Sub

Private Sub CommandButton2_Click()
FormCal.Show
End Sub

Private Sub UserForm_Initialize()

    Set fbd = Sheets("Base facturation")
    Set dico1 = CreateObject("Scripting.Dictionary")
    Set dico2 = CreateObject("Scripting.Dictionary")
    derLn = fbd.Range("C" & Rows.Count).End(xlUp).Row
    For ln = 2 To derLn
        dico1(fbd.Range("C" & ln).Value) = ""
    Next ln
    ComboBox1.List = Application.Transpose(dico1.keys)
    ComboBox3.ColumnCount = 1
 ComboBox3.List() = Array("", "Réglé", "Non Réglé")
End Sub

Bonjour,

Il faut instancier votre Dico2 dans la procédure ComboBox1_Change et pas dans UserForm_Initialize

Private Sub ComboBox1_Change()
    ComboBox2.Clear
    TextBox1 = ""
    TextBox2 = ""
    TextBox3 = ""
    TextBox4 = ""

    Set dico2 = CreateObject("Scripting.Dictionary")
    For ln = 2 To fbd.Range("A" & derLn).Row
        If fbd.Range("C" & ln) = ComboBox1 Then
            dico2(fbd.Range("A" & ln).Value) = ""
        End If
    Next ln
    ComboBox2.List = Application.Transpose(dico2.keys)
    Set dico2 = Nothing

End Sub

merci beaucoup j'ai bien les bonne facture dans combobox2

1 problème de réglé reste mon problème du combobox 3 et texbox5 qui ne vont pas chercher le n° de facture selectionner dans la combobox 2

encore merci

Lorsque vous postez, mettez un fichier d'exemple, sinon cela oblige à modéliser un fichier.

désolé

voila le fichier dans l'onglé facture cliquer sur règlement facture

merci

4facturier-v8.zip (626.51 Ko)
Dim fbd, derLn, ln, dico1, dico2, LigneFacture As Integer

Private Sub ComboBox2_Change()

    TextBox1 = ""
    TextBox2 = ""
    TextBox3 = ""
    TextBox4 = ""
    For ln = 2 To fbd.Range("A" & derLn).Row
        If fbd.Range("C" & ln) = ComboBox1 And fbd.Range("A" & ln) = ComboBox2 Then
            TextBox1 = fbd.Range("K" & ln)
            TextBox2 = fbd.Range("BN" & ln)
            TextBox3 = fbd.Range("CP" & ln)
            TextBox4 = fbd.Range("N" & ln)
            LigneFacture = ln
        End If
    Next ln

End Sub

Private Sub CommandButton1_Click()

    If LigneFacture > 0 Then
       fbd.Range("N" & LigneFacture) = ComboBox3
       fbd.Range("CP" & LigneFacture) = TextBox5
    End If
    Unload Me
End Sub

Private Sub UserForm_Initialize()

    LigneFacture = 0

    Set fbd = Sheets("Base facturation")
    Set dico1 = CreateObject("Scripting.Dictionary")
    'Set dico2 = CreateObject("Scripting.Dictionary")
    derLn = fbd.Range("C" & Rows.Count).End(xlUp).Row
    For ln = 2 To derLn
        dico1(fbd.Range("C" & ln).Value) = ""
    Next ln
    ComboBox1.List = Application.Transpose(dico1.keys)
    ComboBox3.ColumnCount = 1
 ComboBox3.List() = Array("", "Réglé", "Non Réglé")
End Sub

mille merci a toi tous fonctionne

a+

Rechercher des sujets similaires à "reinitialiser combobox probleme modification"