Dim Liste
Private Sub UserForm_Initialize()
'Microsoft ActiveX DataObject doit être coché
' Champ nommé BD
Set cnn = New ADODB.Connection
cnn.Open "DRIVER={Microsoft Excel Driver (*.xls)};ReadOnly=1;DBQ=" & _
ThisWorkbook.Path & "\" & "BDPROD.xls"
Set rs = cnn.Execute("SELECT libellé FROM BD")
Me.ListBox1.List = Application.Transpose(rs.GetRows)
Liste = Me.ListBox1.List
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
Private Sub TextBox1_Change()
Me.ListBox1.Clear
For Each c In Liste
If UCase(c) Like UCase(Me.TextBox1) & "*" Then Me.ListBox1.AddItem c
Next c
End Sub
Private Sub TextBox2_Change()
Me.ListBox1.Clear
For Each c In Liste
If UCase(c) Like "*" & UCase(Me.TextBox2) & "*" Then Me.ListBox1.AddItem c
Next c
End Sub
Private Sub ListBox1_Click()
ActiveCell = Me.ListBox1
Unload Me
End Sub