Solved

help using data in combo boxes

Posted on 2001-08-13
8
141 Views
Last Modified: 2010-05-02
Hello,

Whats the best way of storing a list of 2 columns in a combobox ?
Ie I have a list of forenames  and a list of surnames. I only want to show the forenames but when I pick the forename I wish to use the surname in code.

any ideas?

cheers
Ben
0
Comment
Question by:BBaron
8 Comments
 
LVL 6

Expert Comment

by:VK
ID: 6380608
Take my OCX, it can handle mutiple columns and much more ...
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 50 total points
ID: 6380613
There are a whole host of possibilies here:

1) Use another combo box or listbox to store the surnames and get the appropriate surname by referencing the .List(n) property of the other control.

2) Store the information in an array and get one or both parts from the array referenced by the .ListIndex property of the combo box to get the appropriate element(s).

3) Store the info in a collection, similar idea to 2)

And possibly many more!

The easiest is perhaps 1) though the others may be more useful in some circumstances.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6380617
BY the way, meant to say that in method 1) you would set the visible property of the partner control to false so that it is not displayed to the user.
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6380631
Put the surenames in  collection like this:

Dim Mysurenames As Collection

Set Mysurenames = new Collection
Mysurenames.Add "Smith" , "John"
...

Then you can access the related surename with:
str_surename = Mysurenames("John")

Best regards
WoK ;o)

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 69

Expert Comment

by:Éric Moreau
ID: 6380660
VK, where can we try your OCX?
0
 
LVL 10

Expert Comment

by:GoodJun
ID: 6381221
ComboBox has a ItemData property that is used for this purpose (Display one thing and pass another thing)
For eg. If you have the forname and surname in a array
vDataArray
with cmb1
        For Idx = 0 To UBound(vDataArray, 2)
            .AddItem vDataArray(1, Idx) 'forename
            .ItemData(Idx) = vDataArray(0, Idx) 'surname
        Next
end with

Hope it help
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6383279
GoodJun, using the itemdata property when you already have an array is irrelevant because you can infer the element from the .ListIndex property. It would be handy if the itemdata property stored something other than an integer but it doesn't so in reality you are using an array method as I suggested earlier.
0
 

Author Comment

by:BBaron
ID: 6383289
Cheers Tim,
  Im going with the collection suggestion
 ps watch out for my next one!

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

14 Experts available now in Live!

Get 1:1 Help Now