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