?
Solved

help using data in combo boxes

Posted on 2001-08-13
8
Medium Priority
?
154 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
[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
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
Technology Partners: 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 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…
Suggested Courses

649 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