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