Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Removing Recipients (2003 SP2)

    I'm not sure if this should be here, the Word forum or the Outlook forum. But as tis code runs in Access, I have placed it here.

    Having trouble with the Word.Application.ActiveDocument.MailEnvelope.Item object
    <pre>Dim appWD As Word.Application
    With appWD.ActiveDocument.MailEnvelope.Item
    .Recipients.Add(strBCC).Type = olBCC
    For X = 0 To NumAttachments - 1
    Me![lstSelectedAttachments].ListIndex = X
    .Attachments.Add CStr(Me![lstSelectedAttachments]), , 1, _
    CStr(Me![lstSelectedAttachments].Column(1))
    Next X
    .Send
    All the above work fine.
    While .Recipients.Count > 0 This line produces error.
    Regards,
    Peter

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Removing Recipients (2003 SP2)

    After sending the document, the Item object is no longer valid, you must refer to it anew:

    With appWD.ActiveDocument.MailEnvelope.Item
    .Recipients.Add(strBcc).Type = 3
    For x = 0 To NumAttachments - 1
    Me!<!t>[lstSelectedAttachments]<!/t>.ListIndex = x
    .Attachments.Add CStr(Me!<!t>[lstSelectedAttachments]<!/t>), , 1, _
    CStr(Me!<!t>[lstSelectedAttachments]<!/t>.Column(1))
    Next x
    .Send
    End With
    With appWD.ActiveDocument.MailEnvelope.Item
    Do While .Recipients.Count > 0
    .Recipients.Remove 1
    Loop
    Do While .Attachments.Count > 0
    ' ...
    Loop
    End With

  3. #3
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Removing Recipients (2003 SP2)

    Thanks Hans.
    I did that but still got an error: " 'Method 'MailEnvelope' of object'_Document failed."
    Workaround. I put the removing recipients etc before the loading of the next lot of recipients.
    As this is before the .Send, the object is still valid.

    <pre>With appWD.ActiveDocument.MailEnvelope.Item
    While .Recipients.Count > 0
    .Recipients.Remove 1
    Wend
    While .Attachments.Count > 0
    .Attachment.Remove 1
    Wend
    .Recipients.Add(strBCC).Type = olBCC
    For X = 0 To NumAttachments - 1
    Me![lstSelectedAttachments].ListIndex = X
    .Attachments.Add CStr(Me![lstSelectedAttachments]), , 1, _
    CStr(Me![lstSelectedAttachments].Column(1))
    Next X
    .Send
    End With </pre>


    But how on earth did you know that the object is not valid after the .Send. Very, very impressive.
    Attached Images Attached Images
    Regards,
    Peter

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Removing Recipients (2003 SP2)

    Once again, setting a breakpoint and single-stepping through the code...

  5. #5
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Removing Recipients (2003 SP2)

    I single stepped through the code umpteen times and never realised that the object being no longer valid was the reason for the error.
    Once again very, very impressive.
    Regards,
    Peter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •