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

asked on

population combo with database values.

HOw can I populate a combobox in vb with data from a field in a database. The query I want to use is "Select distinct("Field1") from dbTable"

I want to know how to open the database and get the data into combo.

Thank you.
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
cbo1.additem "whatever" is the correct syntax
ASKER CERTIFIED SOLUTION
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
Avatar of Aiysha

ASKER


The following worked perfect. I still appreciate your input.


Dim conn
Dim rec


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 Distinct STATE from Dataset"
rec.Open (esql), conn, adOpenStatic, adLockReadOnly
If rec.RecordCount > 0 Then
   rec.MoveFirst
    Do Until rec.EOF
        FacilitySelection.CmbState.AddItem rec("STATE")
        rec.MoveNext
    Loop
End If
conn.Close
Set conn = Nothing