Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2015-01-27
3
Medium Priority
?
163 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 28

Accepted Solution

by:
MacroShadow earned 2000 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 49

Expert Comment

by:Dale Fye
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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

886 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