
Problem with Combo Drop Down Lists
Quote:
>I am sooooo frustrated!!!
Goes with the territory doesn't it?
Quote:
>All I want to do is put a combo drop down list on a form, and have it filled
>from a database, but NOT using the Data Control.
>I tried everything...If I use the regular drop down list, I can fill it ok,
>but it doesn't support more than 1 column. For example...I want to have a
>list of clients, but I would like to somehow only show the Client Name, but
>when the user selects the Client Name I would like to get the Client ID.
Yes! this is VERY POSSIBLE. I do it all the time. Keep in mind that
when your user selects the ClientName, you still have to know which
item in the list is selected right? And what you want to do is to
ignore the "item" i.e. the ClientName and get back "data" associated
with that item: i.e. the ClientID
It's called: "Itemdata" read on.....
Quote:
>I have even tried the DB Combo, and that works great, however you have to
>use the data control to fill it.
No you don't. At least you don't in VB3. I don't know about VB5,
BUT, what you're describing is actually very easy.
the drop-down combo has an additional "ItemData" field that most
people don't use. It's designed specifically for keeping a number
(usually a long integer) attached to the combo selection. And it will
do exactly what you want.
When you populate the drop-down, (using Combo1.AddItem "Client Name")
you also add your client ID number to the Itemdata of the combo, then
when your user selects one from the list, you don't have to read the
name associated with the combo array, you just read the Itemdata.
---------------------beginning of example-----------------
ItemData and NewIndex Properties Example
The example fills a list box with employee names and fills the
ItemData array with employee numbers using NewIndex to keep the
numbers synchronized with the sorted list. A label displays
the name and number of an item when the user makes a selection. To
try this example, paste the code into the Declarations section of a
form that contains a list box and a label. Set the Sorted property
for the list box to True. Then press F5 and click the list box.
Sub Form_Load ()
' Fill List1 and ItemData array with
' corresponding items in sorted order.
List1.AddItem "Judy Phelps"
List1.ItemData(List1.NewIndex) = 42310
List1.AddItem "Chien Lieu"
List1.ItemData(List1.NewIndex) = 52855
List1.AddItem "Mauro Sorrento"
List1.ItemData(List1.NewIndex) = 64932
List1.AddItem "Cynthia Bennet"
List1.ItemData(List1.NewIndex) = 39227
End Sub
Sub List1_Click ()
' Append the employee number and the employee name.
Msg = List1.ItemData(List1.ListIndex) & " "
Msg = Msg & List1.List(List1.ListIndex)
Label1.Caption = Msg
End Sub
-------------------end of example---------------------------
One bit of warning: NEVER use the Itemdata stuff without an error
handler.
I use them all the time to do exactly what you're describing.
Quote:
>I can't believe this is this difficult, I used to be able to do this in
>MS-Access in less than 3 minutes tops, but I've been working on this problem
>for about 2-3 weeks now and I'm about ready to either throw my computer or
>myself out the window!
Now now, Let's not do anything rash.
Quote:
>I also do not have the money to purchase controls that have been created for
>this type of purpose, I know they're out there and I wish I could just
>purchase them and be on my merry way, but unfortunately I can't, I have to
>rely on the controls that came with VB5.
Otherwise, how do you like VB5?
Quote:
>Please help, I don't know where else to turn.
>Thanks,
>Kenneth W. Cronin