Solved

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

Posted on 2015-01-27
3
161 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
[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
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 48

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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.

630 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