Reference for Outlook Object Model

M

mixolydian

I am looking for full technical documentation on the Outlook Object
Model. My immediate task is to read and update the Contacts folder
from an Access application.

I use Helen Feddema's DAO Object Model book heavily and would like a
reference for Outlook's Object Model at a similar level of detail.

Thanks

Tom

Mixolydian
 
S

Sue Mosher [MVP]

The most accessible reference is the VBA Help file for Outlook. There was an
Outlook 2000 VBA Programmer's Reference, but it may now be out of print.
 
M

mixolydian

The most accessible reference is the VBA Help file for Outlook. There was an
Outlook 2000 VBA Programmer's Reference, but it may now be out of print.

Thanks Sue. The Help seems to be innacurate or incomplete.

I copied this code and tried it. The Distribution List creates but
AddMember doesn't work for me.

Sub xyz()
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myDistList As Outlook.DistListItem
Dim myRecipients As Outlook.Recipients

Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myDistList = myOlApp.CreateItem(olDistributionListItem)
Set myRecipients = myOlApp.CreateItem(olMailItem).Recipients
myRecipients.Add myNameSpace.CurrentUser.Name
Debug.Print myRecipients.Count '------------------------ prints 1
myDistList.AddMembers myRecipients
Debug.Print myDistList.MemberCount '--------------------- prints 0
myDistList.Display '------displays an empty unnamed list
End Sub

I guess I'll look for a copy of Outlook 2000 VBA Programmer's
Reference. The local Barnes & Noble had books for Excel, Acces, and
Word; nothing for Outlook.

Mixolydian
 
S

Sue Mosher [MVP]

Try using Recipients.Resolve before you try to add them to the DL.

Help definitely has errors, BTW.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
M

mixolydian

An update on my problem, if anyone is interested.

I tried Resolve, but that didn't help.

I then tried to run the program under Outlook instead of Access and it
worked. Hmmmm.

Went back to Access and trapped errors on AddMember and ran Display on
the DistList. I forgot to close the display window.

I reran and Lo! it worked. I surmised that just creating the DistList
item did not make it "active" if the environment was not Outlook, but
Access. Displaying put it in a window and brought it to life.

So I inserted a
myDistList.Display
before updating and a
myDistList.Close olSav
at the end. Does the trick.

I wonder if this behavior has something to do with Explorers or
Inspectors? I just got my "Outlook 2000 VBA" book and will check this
out as well as other instantiation and visiblity rules.

Office is promoted as an integrated set of tools, but this is not
exactly the case. There are different execution environments and this
can cause unexpected behavior.


Try using Recipients.Resolve before you try to add them to the DL.

Help definitely has errors, BTW.
Sub xyz()
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myDistList As Outlook.DistListItem
Dim myRecipients As Outlook.Recipients
Dim rcp As Outlook.Recipient
Dim mli As Outlook.MailItem

Dim Msg As String

Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set mli = myOlApp.CreateItem(olMailItem)
Set myDistList = myOlApp.CreateItem(olDistributionListItem)
myDistList.DLName = "z"
myDistList.Display

Set myRecipients = mli.Recipients

myRecipients.Add "Bob Daniels"
Debug.Print myRecipients.ResolveAll '------------ prints True
Debug.Print myRecipients.Count '------------------------ prints 1

On Error Resume Next ' Defer error handling.
Err.Clear
myDistList.AddMembers myRecipients
' Check for error, then show message.
If Err.Number <> 0 Then
Msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
End If
Debug.Print myDistList.MemberCount '--------------------- prints 0
myDistList.Close olSave

End Sub

Mixolydian
 

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