Solved

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

Posted on 2015-01-27
3
160 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 (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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
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.

752 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