Solved

Populate 1st & 2nd column of a combobox using Access 2013 VBA

Posted on 2015-01-27
3
159 Views
Last Modified: 2015-01-28
I am using Access 2013.

I have a combobox with 2 columns.  The first column is a string. The second column will hold a number
The data just mentioned will be held in a 2 dimensional array, so I want to populate the combobox whilst in a loop.

I can populate the first column easily enough, but am having trouble populating the 2nd column of the combobox.

Would appreciate help.

Thanks.
0
Comment
Question by:peispud
3 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 40574628
Here is a sample:
Private Sub Form_Load()

    Dim arrDemo(0 To 1, 0 To 3) 
    Dim lngPosition As Long

    arrDemo(0, 0) = 1
    arrDemo(0, 1) = 2
    arrDemo(0, 2) = 3
    arrDemo(0, 3) = 4

    arrDemo(1, 0) = "one"
    arrDemo(1, 1) = "two"
    arrDemo(1, 2) = "three"
    arrDemo(1, 3) = "four"

    Me.cboTest.RowSourceType = "Value List"

    For lngPosition = LBound(arrDemo, 2) To UBound(arrDemo, 2)
        Me.cboTest.AddItem arrDemo(0, lngPosition) & ";" & arrDemo(1, lngPosition), lngPosition
    Next lngPosition
    
End Sub

Open in new window

0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40574927
Why not create a table for those values and use the table as the combo boxes recordsource.  This would be far easier to maintain, in the long run, than hard coding it.
0
 

Author Closing Comment

by:peispud
ID: 40574970
To answer Dale Fye,  

I am populating the combo box from different tables based on arguments to the function.


Thanks all for the help.  Excellent!!
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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.

828 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