Results 1 to 2 of 2

Thread: Display data in a combobox

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Horst
    Posts
    262
    Hi group,

    For the last couple of hours(!!!) I am trying to show the contents of a table in a combo box.

    I have table with 2 fields:
    * FunctieID
    * FunctieDescription

    I tried a couple of SQL statements:

    SELECT tblFunctie.FunctieID, tblFunctie.Description

    And

    SELECT tblFunctie.FunctieID, tblFunctie.Description FROM tblFunctie

    I put them in the combobox property: datafield and/or datasource.

    Result => nothing.

    Why doesnt this work. By the way I am using the ADO method.

    Sander

  2. #2
    Hyperactive Member vbuser1976's Avatar
    Join Date
    Sep 2000
    Location
    Yonkers, NY
    Posts
    404

    Lightbulb Okay...kind of long

    Well, first of all, your SQL statement are wrong. You do not have to put the tablename as part of the field name(Select tblone.fieldone, tblone.fieldtwo from tblone). If the table has only those two fields, can make your SQL Statement like this:
    Select * from tblone or
    Select fieldone,fieldtwo from tblone

    I have a lengthy solution to your problem so bear with me. The way I set up to populate my combo box was to use a stored procedure and a set up connection in form load.

    Hope this helps.

    Below is code:
    ##########################################################
    Option Explicit
    Private cn As ADODB.Connection
    Private rs As ADODB.Recordset

    Private Sub Form_Load() 'Opens the database and populates the combobox
    Set cn = New Connection
    cn.Open "PROVIDER=MSDASQL;dsn=QCManager;uid="sa";pwd="";
    database=[name of your dB];"
    Set rs = New ADODB.Recordset
    rs.LockType = adLockOptimistic
    rs.CursorType = adOpenKeyset
    PopulateComboBox
    End Sub

    Private Sub PopulateComboBox() 'This procedure runs a loop to populate the combobox
    Dim rs As ADODB.Recordset
    Dim cm As ADODB.Command

    Set cm = New ADODB.Command
    Set cm.ActiveConnection = cn
    cm.CommandType = adCmdStoredProc
    cm.CommandText = "enter name of stored procedure here"
    Set rs = cm.Execute

    'Comboboxname.Clear
    cbAtmId.Clear
    Do Until rs.EOF
    cbAtmId.AddItem rs.Fields("AtmId")
    rs.MoveNext
    Loop

    rs.Close
    Set rs = Nothing
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width