Solved

help using data in combo boxes

Posted on 2001-08-13
8
142 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 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

23 Experts available now in Live!

Get 1:1 Help Now