Link to home
Start Free TrialLog in
Avatar of Member_2_1242703
Member_2_1242703

asked on

Populating a Combo Box

I have an SQL DB with a table named EmployeeData. It has a column named EmployeeName.

I have a form with a drop down called cmbName

When the form loads I want to populate the drop down in alphabetic order with the data from the EmployeeName column.
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland 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
Avatar of bkthompson2112
bkthompson2112

Hi mwmiller78,

this should do it:

  Dim sSQL As String
  sSQL = "SELECT EmployeName FROM EmployeeData ORDER BY EmployeeName"
         
  Dim rs As ADODB.Recordset
  Set rs = New ADODB.Recordset

  rs.Open sSQL, Conn, adOpenForwardOnly, adLockReadOnly, adCmdText

  Do While rs.EOF = False
    cmbName.AddItem rs.Fields("EmployeeName").Value & ""
    rs.MoveNext
  Loop

  rs.Close
  Set rs = Nothing

bkt
carl_tawn's got it.
(i left the connection object out of mine, sorry)
Great minds think alike :o)
Avatar of Member_2_1242703

ASKER

Sweet. Thanks guys, I see what I was doing wrong now. THANKS!!!