I want to use combobox selected value as query to pull another data from mysql database. Let's say Combobox selected value as id. then I will use this id to pull another details related to this id such as supplier, cost etc. to display in label option. I used following code but it doesn't work.
sqlQa = "select Description from matcat_select where BOF like 'MAIN';"
rs.Open sqlQa, oConn, adOpenStatic
With rs
'Set .ActiveConnection = Nothing 'Disconnect the recordset.
k = .Fields.Count
'Populate the array with the whole recordset.
vaData = .GetRows
End With
'Manipulate the Combobox's properties and show the form.
With UserForm1
With .ComboBox1
.Clear
.BoundColumn = k
.List = Application.Transpose(vaData)
.ListIndex = -1
End With
End With
'Manipulate the Combobox's properties and show the form
Set rs1 = CreateObject("ADODB.Recordset")
sqlQb = "Select EOF From matcat_select Where Description = '" & ComboBox1.Value & "';"
rs1.Open sqlQb, oConn
While Not rs1.EOF
Label6.Caption = rs1("EOF")
rs1.MoveNext
Wend
Please check my code and correct me if I am wrong. Also, each time I made query in mysql via vba am I need to establish a connection?