my code wont attach document

W

WP

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 = "(e-mail address removed)"
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, "(e-mail address removed)"
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
UserForm1.Hide

End Sub
 
D

DA

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
 
W

WP

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 :)
 

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