Private Sub OptionButton1_Click()
cherche (Me.OptionButton1.Caption)
End Sub
Private Sub OptionButton2_Click()
cherche (Me.OptionButton2.Caption)
End Sub
Private Sub OptionButton3_Click()
cherche (Me.OptionButton3.Caption)
End Sub
Private Sub OptionButton4_Click()
cherche (Me.OptionButton4.Caption)
End Sub
Sub cherche(moncode)
Dim rs As ADODB.Recordset
Set cnn = New ADODB.Connection
répertoire = ThisWorkbook.Path & "\"
cnn.Open "DRIVER={Microsoft Excel Driver (*.xls)};DBQ=" & répertoire & "Article.xls"
Set rs = cnn.Execute("SELECT * FROM BD WHERE designation='" & moncode & "'")
Me.ListBox1.Clear
If rs.EOF() Then
Me.TextBox2 = "Inconnu"
Me.TextBox2.BackColor = vbRed 'RGB(255, 0, 0)
Else
Me.TextBox2 = ""
Me.TextBox2.BackColor = vbWhite
i = 0
Do While Not rs.EOF
Me.ListBox1.AddItem rs(1)
'Me.ListBox1.List(i, 1) = rs(1)
'Me.ListBox1.List(i, 2) = rs(2)
'Me.TextBox3 = rs(2)
rs.MoveNext
i = i + 1
Loop
End If
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
Private Sub Listbox1_Click()
Me.TextBox3 = ""
Me.ListBox2.Clear
Dim rs As ADODB.Recordset
Set cnn = New ADODB.Connection
répertoire = ThisWorkbook.Path & "\"
cnn.Open "DRIVER={Microsoft Excel Driver (*.xls)};DBQ=" & répertoire & "Article.xls"
Set rs = cnn.Execute("SELECT * FROM BD WHERE designation='" & ListBox1.Value & "'")
Do While Not rs.EOF
Me.TextBox3 = rs(2)
rs.MoveNext
i = i + 1
Loop
i = 0
Do While Not rs.EOF
Me.ListBox2.List(i, 2) = rs(2)
rs.MoveNext
i = i + 1
Loop
End Sub