?
Solved

help using data in combo boxes

Posted on 2001-08-13
8
Medium Priority
?
156 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 150 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
Independent Software Vendors: 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!

 
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
 
LVL 70

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

840 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