Solved

Populating a Combo Box

Posted on 2004-09-01
6
197 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 250 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

751 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