PDA

Click to See Complete Forum and Search --> : How to use a datacombo in outlook


FunkyDexter
Jun 8th, 2005, 09:56 AM
I want to populate a combo box with all the accounts from a db. I want the account name to show but I want to be able to recover the account id when a user makes a selection.

In Vb I'd do this by using a datacombo, setting it's datasource to a adodb object and setting it's listID to accountName and it's bound column to accountID. Easy.

The trouble is that the datacombo in outlook doesn't seem to have a datasource property (The datagrid didn't have one in it's properties panel either but I was able to set it from code - sadly not the case with the datacombo). So how do you set the datasource for a datacombo in outlook?

Alternatively, is there a way I could use the standard combobox in outlook? I would want it to display the account name without the account id but I'd want ot be able to recover the account id when a user makes a selection.

RobDog888
Jun 8th, 2005, 11:56 AM
You can use a standard combo box. It has a ItemData property that takes a numeric value, one for each Item. So if they select
the 5th item the you can get the .ListIndex property which will be 4 and the .ItemData of that will contain the ID info.

When you populate the combo also populate the .ItemData too.

FunkyDexter
Jun 9th, 2005, 03:25 AM
I looked at the itemdata property but it's not suitable because the id field isn't numeric. As a stop-gap I've set up an id's collection and I'm using the itemdata property of the combobox listitem to store the index of the id in the ids collection but it's all getting a bit messy.

Edit: Actually that's not what I've done (that's the trouble with checking on forums before reminding yourself what you did last thing lastnight :blush: ). The outlook combo doesn't have an itemdata property so I'm actually using the listindex of the combo box as the key when I insert into the id's collection. Like I said though , it's getting messy :eek2:

All told the controls in outlook seem to differ quite substantially from their standard vb counterparts and not for the better.

RobDog888
Jun 9th, 2005, 11:03 AM
Sorry about that.

Another thing you can do is use a second hidden conbo box to hold the alphanumeric id data. The two combos can be easily synced in code
so when the visible one is selected the corresponding hidden combo is changed as well.

FunkyDexter
Jun 9th, 2005, 11:31 AM
I think that's similar to my idea of keeping a collection of id's keyed by the combobox's index isn't it? Ultimately I'd still just be maintaining two collection/list/array thingies and trying to keep them synched. Or is there some extra functionality that the combo would give me that would help?

Anyway, I've got it working using the id's collection and I understand the code... pity the poor sucker who'll have to maintain it when I'm gone though.

RobDog888
Jun 9th, 2005, 11:45 AM
Think of it as job security for the next guy. :)