Newbie wants to connect using CDO instead of MAPI

B

burkejay

I have the following VBA code that uses MAPI to get a user's Appointments.
It generates the dreaded security access dialog, so i want to use CDO
instead, but I don't know how.

Dim ol As New Outlook.Application
Dim olns As Outlook.NameSpace
Dim recip As Outlook.Recipient
Dim rs As Recordset

Set olns = ol.GetNamespace("MAPI")

Set rs = CurrentDb.OpenRecordset("SELECT OUTLOOK_USERID FROM
USER_ACCOUNTS")
rs.OpenRecordset

Set recip = olns.CreateRecipient(rs!OUTLOOK_USERID)
recip.Resolve rem security prompt opens here.

How do I replace the CreateRecipient and resolve with CDO
objects instead?

Thanks!
 
S

Sue Mosher [MVP-Outlook]

Why? CDO 1.21 always raises security prompts.

Is this code for Outlook VBA? If so, this is your problem:

Dim ol As New Outlook.Application

Instead, use the intrinsic Application object that Outlook VBA exposes:

Set ol = Application

or just

Set olns = Application.GetNamespace(MAPI)
 
B

burkejay

Sorry that I failed to mention it is in Access VBA.

I commented out the whole line "Dim ol As New Outlook.Application"
and just did a straight "Set olns = Outlook.Application.GetNamespace("MAPI")"

and I still got the security warning.

Thanks so much for your help!
 
K

Ken Slovak - [MVP - Outlook]

From outside the Outlook VBA, like in Access VBA, you would use New
Outlook.Application.

However, you aren't understanding that the project reference to MAPI is
actually CDO 1.21 and your MAPI.Session is a CDO Session object. CDO is
restricted and no matter what you do if you use it you will get the security
prompts.

I think you are confusing Extended MAPI with CDO (MAPI). Extended MAPI has a
huge learning curve and cannot be programmed using VBA, only C++ or Delphi
in unmanaged code.
 
B

burkejay

My mistake, I had skimmed that very discussion and that was where I got
the idea that I needed to use CDO. I must have misread it, sorry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top