Attachment not appearing.

A

acjharms

I've got a W2K template that generates a summary of selected documents.
The user is presented with a list box to choose which items are to be
summarized. I also want to send the selected documents as Outlook
e-mail attachments. I use this to start the e-mail (In the Userform
initialization)

Private Sub UserForm_Initialize()
~
mailtxt = "Assessments done " + Format(Now(), "mm/dd/yyyy")
Set maildas = CreateObject("Outlook.Application")
Set mailmsg = maildas.CreateItem(olmailItem)
With mailmsg
.To = "ASSEMAIL"
.Subject = mailtxt
.body = mailtxt
End With
End Sub

Then this to add the attachment (runs after the doc is summarized)

~
attdoc=ActiveDocument.FullName
mailmsg.Attachments.Add attdoc, olByValue, atpos, "document"
~

The code runs without an error, but the attachment isn't in the e-mail.
Any ideas? I do have a ref to the Outlook reference library.
 
D

Doug Robbins - Word MVP

ActiveDocument.FullName should return the name of the activedocument.

As a test, add the following command:

mailmsg.Display

after

mailmsg.Attachments.Add attdoc, olByValue, atpos, "document"

and see if the attachment appears.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

acjharms

Thanks, but so far, I've

--.Displayed mailmsg both before and after the Attachments.Add No
luck.
-- replaced attdoc with a filename (C:\test.doc). No joy.
-- If I replace attdoc with a filename that doesn't exist, I get an
error--System can't find filename specified (Whoopie, I know the code's
running!)

I'm wondering if starting the mailmsg in the Intialize sub and then
accessing it in another (both subs in the Userform) may be the issue.
I use pretty much identical code in a single sub in another macro and
it works fine there. I declare mailmsg as a public Object at the start
of the Module.
 
D

Doug Robbins - Word MVP

Splitting the routine like that is quite likely the cause of the problem. I
can't imagine that you really need to start the process in the initialise
event of the user form.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

acjharms

AARRGGGHH!! Now I need to call building maintenance. There's a hole in
the wall where I slammed my forehead.

Compacted the code into a single location in the macro. Still no joy.
Decided to start over, so I did a search on mailmsg in the code so I
could strip it out and....FOUND THE CODE CREATING THE MSG IN AUTONEW
(problem w/ going away for a week in the middle of a project). Removed
that version, some additional tweaks.and I'm good to go. Thanks for
the assist.
 

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