Combobox et vba sous excel

cs_PierreCo Messages postés 2 Date d'inscription jeudi 6 février 2003 Statut Membre Dernière intervention 14 novembre 2003 - 12 nov. 2003 à 14:54
cs_PierreCo Messages postés 2 Date d'inscription jeudi 6 février 2003 Statut Membre Dernière intervention 14 novembre 2003 - 14 nov. 2003 à 08:22
Je travaille sur Excel et j'ai un userform qui a un combobox.
J'aimerais que ce combobox soit rempli à partir d'une table Access et qu'il ait deux colonnes.

2 réponses

cs_wape Messages postés 262 Date d'inscription samedi 21 décembre 2002 Statut Membre Dernière intervention 19 décembre 2010 12
13 nov. 2003 à 22:55
Voici un exemple avec DAO 3.6 (Access 2000) :

Private Sub CommandButton1_Click()

'Sélectionner "Microsoft DAO 3.6 Object Library" dans Outils/Références...

Dim i As Integer
Dim Db As Database
Dim Rs As Recordset

Set Db = OpenDatabase("C:\MaBase.mdb")
Set Rs = Db.OpenRecordset("MaTable")

i = 0
ComboBox1.Clear
Do While Not Rs.EOF
ComboBox1.AddItem Rs!MonChamp1
ComboBox1.List(i, 1) = Rs!MonChamp2
i = i + 1
Rs.MoveNext
Loop

Rs.Close
Db.Close

End Sub

N.B. Mettre la propriété "ColumnCount" du ComboBox à 2

Slts

wape
0
cs_PierreCo Messages postés 2 Date d'inscription jeudi 6 février 2003 Statut Membre Dernière intervention 14 novembre 2003
14 nov. 2003 à 08:22
Merci beaucoup, cela me rend un grand service.
0
Rejoignez-nous