Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

my code wont attach document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WP - 26 Apr 2007 16:04 GMT
I can get this code to send an email through lotus notes but the email i get
doesnt have an attachment. I created a userform that the user enters his text
in then the submit button fills in the bookmarks. I have an email button that
when clicked it sends an email to me but no attachment
Any help is greatly appreciated
TIA

Public Sub CommandButton2_Click()

'SendNotesMail(Subject As String, Attachment As String, Recipient As String,
BodyText As String, SaveIt As Boolean)
'Set up the objects required for Automation into lotus notes
   Dim Maildb As Object 'The mail database
   Dim UserName As String 'The current users notes name
   Dim MailDbName As String 'THe current users notes mail database name
   Dim MailDoc As Object 'The mail document itself
   Dim AttachME As Object 'The attachment richtextfile object
   Dim Session As Object 'The notes session
   Dim EmbedObj As Object 'The embedded object (Attachment)
   'Start a session to notes
   Set Session = CreateObject("Notes.NotesSession")
   'Next line only works with 5.x and above. Replace password with your
password
   'Session.Initialize ("xxxxxxx")
   'Get the sessions username and then calculate the mail file name
   'You may or may not need this as for MailDBname with some systems you
   'can pass an empty string or using above password you can use other
mailboxes.
   UserName = Session.UserName
   MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) -
InStr(1, UserName, " "))) & ".nsf"
   'Open the mail database in notes
   Set Maildb = Session.GETDATABASE("", MailDbName)
    If Maildb.IsOpen = True Then
         'Already open for mail
    Else
        Maildb.OPENMAIL
    End If
   'Set up the new mail document
   Set MailDoc = Maildb.CREATEDOCUMENT
   MailDoc.Form = "Memo"
   MailDoc.sendto = "xxxxx@cxxxxx.com"
   MailDoc.Subject = "Literature request"
   MailDoc.Body = BodyText
   MailDoc.SAVEMESSAGEONSEND = SaveIt
   'Set up the embedded object and attachment and attach it
   If Attachment <> "" Then
       Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
       Set EmbedObj = AttachME.EmbedObject(1454, "", Attachment,
"Attachment")
       MailDoc.CREATERICHTEXTITEM ("Attachment")
   End If
   'Send the document
   MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items
folder
   MailDoc.SEND 0, "xxx@xxxxxx.com"
   'Clean Up
   Set Maildb = Nothing
   Set MailDoc = Nothing
   Set AttachME = Nothing
   Set Session = Nothing
   Set EmbedObj = Nothing
   UserForm1.Hide
   
End Sub
DA - 27 Apr 2007 05:54 GMT
Ok, maybe I'm not seeing this correctly, but what are you actually trying to
do in this bit of your code? (see questions below)

>     If Attachment <> "" Then
>         Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
>         Set EmbedObj = AttachME.EmbedObject(1454, "", Attachment,
> "Attachment")
>         MailDoc.CREATERICHTEXTITEM ("Attachment")
>     End If

Questions I'd pose are:
1) Firstly, have you stepped through the routine and are certain the code is
going into the IF routine you've set up?
2) You set EmbedObj, but are not doing anything with it?
3) In the line "MailDoc.CREATERICHTEXTITEM ("Attachment")" it looks like
you're passing the word "Attachment" as a string, not the string that the
variable holds.

Dennis

> I can get this code to send an email through lotus notes but the email i get
> doesnt have an attachment. I created a userform that the user enters his text
[quoted text clipped - 61 lines]
>    
> End Sub
WP - 27 Apr 2007 13:38 GMT
Hi Dennis
I should let you know that I am fairly new to this and have been using code
that I have been able to find on the net. the only code I did myself was the
bookmarking.
I am not sure how or what I should insert to make this work
Please help :)

> Ok, maybe I'm not seeing this correctly, but what are you actually trying to
> do in this bit of your code? (see questions below)
[quoted text clipped - 81 lines]
> >    
> > End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.