Solved

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

Posted on 2015-01-27
3
149 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 26

Accepted Solution

by:
MacroShadow earned 500 total points
Comment Utility
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)
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server views 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 Access…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now