PDA

View Full Version : Problem Accessing the GAL using CDO



blueben
04-13-2011, 07:36 AM
Hi,

As part of a user form I've deisgned, I have some code which allows users to select a recipient from the Global Address book and have specific details saved to a text box (see relevant part below).

Unfortunately this is only working on selected machines. It is fine on some but others the 'Set recipients' part is simply skipped with no error message to determine why. I understand that this is due an issue of the CDO object no longer being supported - however I designed the tool in Outlook 2010 and all my users (both those that work and those that don't) have 2007.

Does anyone have any idea how to resolve this; or if not how I can achieve the same using the Outlook 2010 object model.

Thank you

Set appOutlook = CreateObject("Outlook.Application")
Set CDOSession = appOutlook.CreateObject("MAPI.Session")
CDOSession.Logon "", "", False, False, 0
Set Recipients = CDOSession.addressbook(Nothing, "Select Employee", False, True, 1, "To:", "", "", 0)

JP2112
04-18-2011, 07:35 AM
I don't see why you wouldn't do it this way:Set appOutlook = CreateObject("Outlook.Application")Set CDOSession = CreateObject("MAPI.Session")
Something is wrong with the post editor, I can't seem to format my code properly. The above code should be two lines.

blueben
04-26-2011, 08:03 AM
I don't see why you wouldn't do it this way:Set appOutlook = CreateObject("Outlook.Application")Set CDOSession = CreateObject("MAPI.Session")
Something is wrong with the post editor, I can't seem to format my code properly. The above code should be two lines.

Thank you for your reply - I made the suggested changes but I didn't have any effect unfortunately.

I'm finding it a bit difficult to believe that this isn't widely known - surely calling the address book via VBA is a fairly common requirement?

JP2112
04-26-2011, 09:00 AM
See if the NameSpace.GetSelectNamesDialog will work. If you need sample code see http://office.microsoft.com/en-us/outlook-help/HV080802366.aspx

blueben
04-27-2011, 12:55 AM
Thank you for the tip - I have been able to bring up the address picker using it.

Next problem: Using the CDO method, I was able to select a recipient and then interrogate it's field list to bring back a piece of information (the employee's ID). This worked as below.

empnovalue = Recipients.Item(1).AddressEntry.Fields(31).value

However when using the NameSpace method the recipient object no longer has a 'Fields' child group and I am unable to find the data anywhere else in the object tree. Do you know how I can resolve this?

I'm fairly new to this so any further help would be appreciated.