Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Populating a Combo Box

Posted on 2004-09-01
6
Medium Priority
?
199 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:Mike Miller
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 1000 total points
ID: 11957351
Add a reference to the ActiveX Data Object libraries. The add code something like:    

    Dim oConn As New ADODB.Connection
    Dim oRS As ADODB.Recordset

    oConn.Open "Your connection string here"
    Set oRS = oConn.Execute("SELECT EmployeeName FROM EmployeeData ORDER BY EmployeeName")

    oRS.MoveFirst

    If Not oRS.BOF And Not oRS.EOF Then
        While Not oRS.EOF
            Combo1.AddItem oRS("EmployeeName")
            oRS.MoveNext
        Wend
    End If

    oConn.Close

    Set oRS = Nothing
    Set oConn = Nothing

Hope this helps.
0
 
LVL 6

Expert Comment

by:bkthompson2112
ID: 11957358
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
0
 
LVL 6

Expert Comment

by:bkthompson2112
ID: 11957367
carl_tawn's got it.
(i left the connection object out of mine, sorry)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 52

Expert Comment

by:Carl Tawn
ID: 11957400
Great minds think alike :o)
0
 
LVL 6

Expert Comment

by:bkthompson2112
ID: 11957442
Yep
0
 

Author Comment

by:Mike Miller
ID: 11957522
Sweet. Thanks guys, I see what I was doing wrong now. THANKS!!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question