Bonjour,
J'ai un pb lorsque j'essais de lire une collection de commune pour charger une combo.
Il boucle sur le dernier élement et je ne vois pas trop pourquoi.
-- Classe Commune
-- Méthode de chargement
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 Private commune As String Private codePostal As String Private departementName As String Private departementCode As String Public Property Get communeOut() As String communeOut = commune End Property Public Property Let communeIn(communeIn As String) commune = communeIn End Property Public Property Get codePostalOut() As String codePostalOut = codePostal End Property Public Property Let codePostalIn(codePostalIn As String) codePostal = codePostalIn End Property Public Property Get departementNameOut() As String departementNameOut = departementName End Property Public Property Let departementNameIn(departementNameIn As String) departementName = departementNameIn End Property Public Property Get departementCodeOut() As String departementCodeOut = departementCode End Property Public Property Let departementCodeIn(departementCodeIn As String) departementCode = departementCodeIn End Property
Je souhaites charger une collection de classe commune en clef (commune name + code postal)
-- Méthode de Lecture : pour charger ma combo
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 Public Function chargeCommuneListe() Set chargeCommuneListe = New Collection Dim texte_Sql As String Dim Cn As ADODB.Connection Dim Cd As ADODB.Command Dim Rst As ADODB.Recordset 'Les données à insérer: Set Cn = New ADODB.Connection Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & classeurExcelCodePostal & ";" & _ "Extended Properties=""Excel 8.0;HDR=No;"";" texte_Sql = "SELECT * FROM [" & feuilleExcelCodePostal & "$" & "]" Set Rst = New ADODB.Recordset Set Rst = Cn.Execute(texte_Sql) Do Until Rst.EOF If Rst(0).Value <> " " Then Dim commune As New commune Dim departementCode As String departementCode = Rst(1).Value With commune .communeIn = Rst(0).Value .codePostalIn = Rst(1).Value .departementNameIn = Rst(2).Value .departementCodeIn = Mid(departementCode, 1, 2) End With chargeCommuneListe.Add commune, commune.communeOut & commune.codePostalOut End If Rst.MoveNext Loop Rst.Close Cn.Close Set Cn = Nothing End Function
Merci pour votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 Sub loadComboBox() Dim i As Long feuilleExcelCombo = "Client" comboBoxName = "comboCommuneDomicile" For i = 1 To communeListe.Count Set commune = communeListe.Item(i) With ActiveWorkbook.Sheets(feuilleExcelCombo).OLEObjects(comboBoxName).Object .AddItem commune.communeOut End With Next i End Sub
Partager