Link to home
Start Free TrialLog in
Avatar of Aiysha
AiyshaFlag for United States of America

asked on

Getting value in a combobox based another combo.

How can I populate the combo2 from the value in combo1 both of these values are obtained from database. The following code is suppsed to do it however the program doesnt read this code when I change the selection in combo1

Private Sub CmbState_Change()   <---Is this the right function name?
Dim conn
Dim rec
Dim myvalue

myvalue = Me.CmbState.Text

Set conn = New ADODB.Connection
Set rec = New ADODB.Recordset
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Database.mdb;Persist Security Info=False"
esql = "select BAT from Dataset where STATE = " & myvalue & ";"
rec.Open (esql), conn, adOpenStatic, adLockReadOnly
If rec.RecordCount > 0 Then
   rec.MoveFirst
    Do Until rec.EOF
        FacilitySelection.CmbBat.AddItem rec("STATE")
        rec.MoveNext
    Loop
End If
conn.Close
Set conn = Nothing

End Sub
ASKER CERTIFIED SOLUTION
Avatar of g_johnson
g_johnson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial