Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Programatically populate a combo box from a recordset

Posted on 2008-06-17
3
Medium Priority
?
593 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 500 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 500 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

Independent Software Vendors: 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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

688 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