Create New E-Mail w/ Attachment to View

I am having a problem creating a Lotus Notes e-mail from Microsoft Access with an attachment. The important part is that I do not want to send the e-mail, I just want it created with the attachment. This way the user can then add any additional text they desire to the e-mail before they send it.

Below is the code I have but I can not view the new e-mail created, it is like it never got created.

Any help would be greatly appreciated.

Dim session As NotesSession

Dim MailDb As NotesDatabase

Dim MailDoc As NotesDocument

Dim oAttachME As Domino.NotesRichTextItem

Dim oEmbedObj As Domino.NotesEmbeddedObject

Dim strAttachmentName As String

Dim ProPath As String

Dim response As String

'Purpose: Start a session to notes

Set session = CreateObject(“Lotus.NotesSession”)

Call session.Initialize(LotusPassword)

'Purpose: Open the mail database in Lotus Notes

Set MailDb = session.GetDatabase(ServerName, MailFile)

If MailDb.IsOpen = True Then

 'Already open for mail

Else

 Call MailDb.Open

End If

'Purpose: Set up the new mail document

Set MailDoc = MailDb.CreateDocument

‘Purpose: Builds the path for the file

strAttachmentName = ProPath & lstIssueAttachments.Column(1)

Set oAttachME = MailDoc.CreateRichTextItem(“Attachment1”)

Set oEmbedObj = oAttachME.EmbedObject(1454, “”, strAttachmentName, “Attachment1”)

'MailDoc.CreateRichTextItem (“Attachment1”) – if I leave this code uncommented, I get the error “Rich Text item Attachment1 already exists

Subject: RE: Create New E-Mail w/ Attachment to View

Since you want to use the Notes UI, you will need to use OLE rather than COM. So instead of…

Set session = CreateObject(“Lotus.NotesSession”)

Call session.Initialize(LotusPassword)

Set MailDb = session.GetDatabase(ServerName, MailFile)

do this:

Set session = CreateObject(“Notes.NotesSession”)

’ Initialize not required for OLE.

Set MailDb = session.GetDatabase(“”, “”)

MailDB.OpenMail

It is not necessary for your program to know the user’s Notes password or the path of their mail file. They may be challenged for their password, however, if Notes is not already running.

To create an attachment, you should first create the rich text item that will contain the attachment. The rich text item in a memo is called Body, not Attachment1. You should also assign the Form field to “Memo” so that Notes will know this is a memo as opposed to a calendar entry or other mail-related form.

Set oAttachME = MailDoc.CreateRichTextItem(“Body”)

Set oEmbedObj = oAttachME.EmbedObject(1454, “”, strAttachmentName)

Call MailDoc.ReplaceItemValue(“Form”, “Memo”)

Call oAttachME.Update( ) ’ complete any pending rich text changes

At this point you have a document that exists only in memory. You want the user to edit it on screen. For that, you need a handle to the Notes UI so that you can display the document to the user:

Set oNotesWS = CreateObject(“Notes.NotesUIWorkspace”)

Call oNotesWS.EditDocument(True, MailDoc)

AppActivate “Lotus Notes” ’ bring Notes to the foreground.

Subject: Create New E-Mail w/ Attachment to View

Just try the following code:

Set oAttachME = MailDoc.CreateRichTextItem(“Body”)

Set oEmbedObj = oAttachME.EmbedObject(1454, “”, strAttachmentName)

MailDoc.Form = “Memo”

'Purpose: Opening the new document

Dim ws As New NotesUiWorkspace

Call ws.EditDocument( True, MailDoc )

Subject: RE: Create New E-Mail w/ Attachment to View

Thanks to both of you for the response but neither of them are working for me and I have tried and tried to get it.

Below is what I have…

Dim session As NotesSession

Dim MailDb As NotesDatabase

Dim MailDoc As NotesDocument

Dim oAttachME As Domino.NotesRichTextItem

Dim oEmbedObj As Domino.NotesEmbeddedObject

Dim oNotesWS As Object – would like to DIM it as NotesUIWorksapce

Dim strAttachmentName As String

Set session = CreateObject(“Lotus.NotesSession”)

Call session.Initialize(LotusPassword)

Set MailDb = session.GetDatabase(ServerName, MailFile)

If MailDb.IsOpen = True Then

     'Already open for mail

Else

     Call MailDb.Open

End If

Set MailDoc = MailDb.CreateDocument

strAttachmentName = ProPath & lstIssueAttachments.Column(1)

Set oAttachME = MailDoc.CreateRichTextItem(“Body”)

Set oEmbedObj = oAttachME.EmbedObject(1454, “”, strAttachmentName)

Call MailDoc.ReplaceItemValue(“Form”, “Memo”)

Set oNotesWS = CreateObject(“Notes.NotesUIWorkspace”) – The only way I can get this statement to work is if I DIM it as an object instead of an NotesUIWorkspace which I think I should be DIM it as. Any thoughts?

Call oNotesWS.EDITDOCUMENT(True, MailDoc) – Here is where my code is stopping. Access is telling me: Rune-time Error 7419 – Incorrect argument type: Object Expected.

Do either of you have any thoughts… I fell like I am so close and would LOVE to get this to work.

Below are the problems I had with your suggestions

MailDoc.Form = “Memo” - Access tells me that the object does not support this property. Do you know how I can correct this? I change it to Call MailDoc.ReplaceItemValue(“Form”, “Memo”) and it worked.

Set session = CreateObject(“Notes.NotesSession”) gave my a type mismatch unless I changes session to an object.

Then Set oAttachME = MailDoc.CreateRichTextItem(“Body”) gave me an Object variable or with block variable not set.

I really like DIM’ing variables with exactly what they are so when I am working in Access with the VBA code, the functions and property suggestions are given to me by Access. This allows me to find things I did not even know existed.

Thanks again for the help.

Subject: RE: Create New E-Mail w/ Attachment to View

Hi Darren,I’m not shure if i can really help you, because I dind’t write much VBA. Perhaps you can DIM the MailDoc as Domino.NotesDocument?

Henning

Subject: RE: Create New E-Mail w/ Attachment to View

Henning

What does putting Domino in front of NotesDocument do? Is there a difference in Domino.Notes Document and just NotesDocument?

Thanks

Darren

Subject: RE: Create New E-Mail w/ Attachment to View

Henning

One other question, I saw some other posts that said you have to first save the mail item before you can open it for edit. Such as:

Call MailDoc.save (True, False)

Is this true?

Thanks

Darren

Subject: RE: Create New E-Mail w/ Attachment to View

No, you do not have to save it. You do, however, either have to use Update on the rich text field, or ComputeWithForm. Otherwise, you will not see all the rich text you put in.

Subject: RE: Create New E-Mail w/ Attachment to View

Hi Darren,i expect that when you are accessing Notes-Classes from other applications, you can tell the compiler where to find the class-description by using the prefix “Domino.”.

When you create a NotesDocument in Domino Backend, and that’s what your code does, you don’t have to save it before opening it in Notes Frontend - but if you don’t open it in Notes Frontend you will lose it if you don’t save it.

Best regards,

Henning

Subject: RE: Create New E-Mail w/ Attachment to View

Henning

Thanks for your time. If I get it to work, I will respond to this post.

Darren

Subject: RE: Create New E-Mail w/ Attachment to View

Henning

From the help of Andre, we got it to work.

Below is the code.

'Purpose: OLE stands for Object Linking and Embedding. This is the style of code that is

’ used below since it refers to an automated technology that predates COM in the

’ Windows world. There is a problem with this and that is the code is late-bound

’ to the target objects. The actual properties and methods for the objects

’ declared aren’t exposed until run-time. The code is therefore slower and much

’ more prone to error.

’ COM stands for Component or Common Object Model which tightly binds the calling

’ code to the COM server, in this case the Notes client back-end objects. The

’ problem is that COM objects do not include UI features, which is why OLE has to

’ be used. Benefits of using COM is that e-mails would be sent using the Notes

’ client with all of the security features such as encryption when desired,

’ electronic signitures, etc.

Dim ProPath As String

Dim response As String

'Purpose: The below variables must be defined as Objects since OLE is being used. If COM

’ was being used, then the variables could be defined as specific Notes objects

’ such as NotesDatabase or NotesDocument.

Dim session As Object

Dim MailDb As Object

Dim MailDoc As Object

Dim oAttachME As Object

Dim oEmbedObj As Object

Dim uiWS As Object

Dim uiDoc As Object

Dim strAttachmentName As String

ProPath = Forms!frmConfig!DBDataPath & "\Attachments" & Forms!frmMain!IssueID & ""

'Purpose: Start a session to notes. This process uses OLE instead of COM since

’ “Notes.NotesSession” is used instead of “Lotus.NotesSession”

Set session = CreateObject(“Notes.NotesSession”)

'Purpose: Opens the mail database

Set MailDb = session.GetDatabase(ServerName, MailFile)

If MailDb.IsOpen = True Then

'Already open for mail

Else

Call MailDb.Open

End If

'Purpose: Set up the new mail document

Set MailDoc = MailDb.CreateDocument

'Purpose: This is the path to the attachment

If lstIssueAttachments.Column(2) = True Then

strAttachmentName = lstIssueAttachments.Column(1)

Else

strAttachmentName = ProPath & lstIssueAttachments.Column(1)

End If

'Purpose: Creates the e-mail body and inserts the attachment

Set oAttachME = MailDoc.CreateRichTextItem(“Body”)

Set oEmbedObj = oAttachME.EmbedObject(1454, “”, strAttachmentName)

'Purpose: Completes any rich text changes

Call oAttachME.update

'Purpose: Sets a special field value to tell Lotus Notes which form to use when opening

’ the document. The assignment of the Form field is just like the assignment of any

’ field. Just setting a value for the Form field, does not do anything by itself

’ except set the value of a field. However, the field name “Form” has a special meaning

’ to Notes when you open the document on-screen (which you are about to do with

’ EditDocument). Notes uses this field to decide which form to use to present the

’ document.

Call MailDoc.ReplaceItemValue(“Form”, “Memo”)

'Purpose: At this point you have a document that exists only in memory. In order to

’ allow text to be added to the message in Lotus Notes, you need the Notes UI

’ so that you can display the document to the user. This is allowing them to

’ edit the message while it is in memmory.

Set uiWS = CreateObject(“Notes.NotesUIWorkspace”)

Call uiWS.EDITDOCUMENT(True, MailDoc)

'Purpose: Brings Lotus Notes to the foreground

AppActivate “Lotus Notes”

'Purpose: By setting the below fields to nothing, it frees up memory used to run this routine

Set session = Nothing

Set MailDb = Nothing

Set MailDoc = Nothing

Set oAttachME = Nothing

Set oEmbedObj = Nothing

Set uiWS = Nothing

Set uiDoc = Nothing

'Purpose: Error number 3000 occurs when Lotus Notes is not open and the user tries to attach

’ an attachment

’ Error number 13 occurs when the users Lotus Notes Mail Server Name or Mail File are

’ not correct.

Err_Email:

If Err.Number = 3000 Or Err.Number = 13 Then

Set session = Nothing

Set MailDb = Nothing

Set MailDoc = Nothing

Set oAttachME = Nothing

Set oEmbedObj = Nothing

Set uiWS = Nothing

Set uiDoc = Nothing

If Err.Number = 3000 Then

response = MsgBox(“Lotus Notes should be open with the attachment and e-mail ready to send. Just go to Lotus Notes to send the e-mail.”, vbOKOnly + vbInformation, “Go to Lotus Notes”)

Else

response = MsgBox(“Please double check your Mail Server Name and Mail Name in the Administration menu under the Team Members form, Admin tab.”, vbOKOnly + vbExclamation, “Mail Server Name / Mail File Error”)

End If

Resume Exit_Sub

Else

lngError = Erl

ctrlfnctnm = “CreateEmailWithAttachment”

Call frmIssueAttachments_err(Err.Number, Err.Description, Err.Source, ctrlfnctnm, lngError)

Resume Exit_Sub

End If