Solved

Populating a Combo Box

Posted on 2004-09-01
6
193 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:mwmiller78
  • 3
  • 2
6 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
carl_tawn's got it.
(i left the connection object out of mine, sorry)
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
Great minds think alike :o)
0
 
LVL 6

Expert Comment

by:bkthompson2112
Comment Utility
Yep
0
 

Author Comment

by:mwmiller78
Comment Utility
Sweet. Thanks guys, I see what I was doing wrong now. THANKS!!!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now