Solved

Programatically populate a combo box from a recordset

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

773 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