Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


populating a combo box

metal_manmetal_man Member Posts: 9
vb begginer needs help to populate a combo box from a locations table.
the table is locationinfodb.mdb all i need is the location codes populated. thank you for any help on this.


  • SanganakSakhaSanganakSakha Member Posts: 8
    Hello metal_man,

    What you need to do is to get the values of individual location codes and add them to the combo box using its list property in the Form_load event of the form that contains the combo.

    I would be glad to provide any more help you may need in this regard.

    with best compliments,

    Your Friend In Need.

  • DroopyADroopyA Member Posts: 175
    I might be a little late with this but here's a Sub I use all the time to populate my combo boxes. This works really well if you need to populate many combo boxes with diffrent fields from diffrent Tables on the same form. You will have to call it for every combo box passing the Table Name, The Filed You Want Populated From The Table and The name of the combo box.

    IE: Call PopulateForm(Employee, FirstName, cboEmployee)
    Call PopulateForm(Office, RoomNumber, cboRoom)

    Private Sub PopulateForm(strRecordName As String, strFieldName As String, cboCombo As ComboBox)
    'N473 *************************************************** N473
    'N473 * Populates All The Combo Boxes On The Form * N473
    'N473 *************************************************** N473

    Dim strDBLocation As String ' Holds The Database Location
    Dim cn As ADODB.Connection ' Active X Connection
    Dim rs As ADODB.Recordset ' Active X Recordset

    ' Clear Old Data

    ' Connect To The Database
    strDBLocation = GetDatabase ' modDatabase
    Set cn = New ADODB.Connection
    cn.Open strDBLocation

    ' Open A Recordset
    Set rs = New ADODB.Recordset
    rs.CursorType = adOpenKeyset
    rs.LockType = adLockOptimistic
    rs.Source = strRecordName
    rs.ActiveConnection = cn

    If rs.BOF = False Or rs.EOF = False Then
    End If

    While rs.EOF = False
    cboCombo.AddItem (rs.Fields(strFieldName))

    rs.Close ' Close The Recordset
    cn.Close ' Close The Connection

    Set rs = Nothing ' Set The Recordset To Nothing
    Set cn = Nothing ' Set The Connection To Nothing

    End Sub

    Hope That Helps

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    ________ [ ] free video tutorials and ebooks about || Perl Objective-C MATLAB R PL/SQL Go Swift C Java Ruby Visual Basic Delphi Assembly Scratch C++ PHP Python Visual Basic .NET JavaScript C# D Erlang Alice Lisp Julia Scheme Hack Clojure ML Dart Bash Awk Transact-SQL Rust Logo VBScript F# Prolog Apex COBOL FoxPro Lua SAS Kotlin Fortran Scala LabVIEW Ada Crystal ABAP || ___

Sign In or Register to comment.