Solved

Programatically populate a combo box from a recordset

Posted on 2008-06-17
3
577 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

733 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