Solved

Programatically populate a combo box from a recordset

Posted on 2008-06-17
3
586 Views
Last Modified: 2013-11-28
Hi,

I have work out the following code to populate my combo box:

'Populating dropdown of Format
    Dim sqlFormat As String
    sqlFormat = "SELECT tblRef_Chartez.libelle FROM tblRef_Chartez ORDER BY tblRef_Chartez.libelle ASC"
    Set rs = con.OpenRecordset(sqlFormat)
    If rs.EOF Then
           'Me.cboFormat.AddItem ("Table is empty")
           Me.cboFormat.RowSource = "Table est vide"
    Else
        While (Not (rs.EOF))
            'Me.cboFormat.AddItem (rs(0)0
            Me.cboFormat.RowSource = Me.cboFormat.RowSource & (rs(0))
            rs.MoveNext
        Wend
    End If
    'End of dropdown

As the method AddItem doesn't work on Ms Access 2000, I did some research and I found that I can populate the combo box by RowSource method.
But to my surprise, I can get the item in the combo box but at one row level only.  All the items are shown mixed together on one line only.  

Can someone help me out please.  

Should I use another method other than RowSource or my code contains errors.

Regards
0
Comment
Question by:AVSTEL
[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
  • 2
3 Comments
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 125 total points
ID: 21803971
Try adding a semicolon delimiter after each item:

> Me.cboFormat.RowSource = Me.cboFormat.RowSource & (rs(0))
change to:

Me.cboFormat.RowSource = Me.cboFormat.RowSource & (rs(0)) & ";"
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 125 total points
ID: 21803994
And also make sure the rowsource type is Value List.  This can be done either through the property sheet or through VBA code.
0
 

Accepted Solution

by:
AVSTEL earned 0 total points
ID: 21804094
Great. It works.

Thx Buddy.  You saved me.

My best regards.
0

Featured Post

Veeam gives away 10 full conference passes

Veeam is a VMworld 2017 US & Europe Platinum Sponsor. Enter the raffle to get the full conference pass. Pass includes the admission to all general and breakout sessions, VMware Hands-On Labs, Solutions Exchange, exclusive giveaways and the great VMworld Customer Appreciation Part

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

622 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