Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding attachment from Ole Object to Body of Email (LN) via VBA 1

Status
Not open for further replies.

claytonjgordon

Technical User
Jul 21, 2004
37
US
I'm trying to take an attachment saved in an Ole Object field on my main Access form and attach it to the body of an Email (using Lotus Notes).

I was write the code to send the Email but I must not be doing the Attachment part correctly because it just shows up as something like |$| instead of the attachment.

I'm useing a Module to send the Email that works as follows:

Code:
Option Compare Database
Option Explicit


Function SendEmail(sendto As String, copyto As String, acct As String, InvName As String, WrkType As String, Purpose As String, Key As String, Attachments As Object)'this last object isn't working


On Error GoTo Local_Err

    Dim session 'As New NotesSession
    Dim db 'As NotesDatabase
    Dim doc 'As NotesDocument
    Dim object 'As NotesEmbeddedObject
           
   Dim Filename
    
    
    Set session = CreateObject("Notes.NotesSession")
    Set db = session.CURRENTDATABASE
    Set doc = db.CREATEDOCUMENT()
    
    
    doc.Form = "Memo"
    doc.sendto = sendto
    doc.copyto = copyto
    doc.Subject = "WIRED: " & acct & ", " & InvName & ", " & WrkType & ", " & Purpose & ", Reference Number: " & Key
    doc.Body = "Referal sent.  Please check the WIRED application for more information. " & vbCrLf _
    & Attachments 'this isn't working
    
                       
                       
    Call doc.SEND(False)
    
    Set doc = Nothing
    Set db = Nothing

Exit Function
Local_Err:
    If Err.Number = 7294 Then
        MsgBox "Can't find person in your Directory!"
    Else
        MsgBox "Lotus Notes must be running on this workstation."
    End If

Exit Function
End Function



This is activated by a button on the form:



Code:
Private Sub Submit_Click()

If IsNull(Me.Acct_) Then
MsgBox "Please enter Acct Number."
Me.Acct_.SetFocus

ElseIf IsNull(Me.InvName) Then
MsgBox "Please enter investor Name."
Me.InvName.SetFocus

ElseIf IsNull(Me.WrkType) Then
MsgBox "Please enter the work type."
Me.WrkType.SetFocus

ElseIf IsNull(Me.Purpose) Then
MsgBox "Please enter the Purpose."
Me.Purpose.SetFocus

Else
SendEmail "Clayton Gordon", "Clayton Gordon", Me.Acct_, Me.InvName, Me.WrkType, Me.Purpose, Me.Key, Me.Attachments 'last field not transfering

End If

DoCmd.Save
MsgBox "Request has been sent to Investor Relations.  Your reference number is: " & Key


End Sub

Any idea what I'm doing wrong here?




Dominus Nihil
(Master of Nothing)
 
Does anyone have any ideas?

Someone at work suggested the 'EMBEDOBJECT method' but was unable to explain what this method is or how to accomplish it.

Anyone familar with this and have some examples of code?


Dominus Nihil
(Master of Nothing)
 
Hi Clayton

If the OLE object is linked to a file, you can certainly attach it. Firstly, define your attachment parameter as a string, which you supply with the source file name of the OLE object when you run the procedure.

In your code, declare the objects you need.

Code:
Dim objAttach as Object 'This is the attachment object
Dim objEmbedded as Object 'This is the embedded object

Then, in the main body of your code, where you're creating the mail, set the attachment object to be a rich text item of type attachment, and then set the embedded object to be that rich text item. Finally, assign it to the maildoc.

Code:
Set objAttachment = MailDoc.CREATERICHTEXTITEM("Attachment")
Set objEmbedded = AttachME.EMBEDOBJECT(1454, "", Attachments, "Attachment")
MailDoc.CREATERICHTEXTITEM ("Attachment")

For an excellent procedure showing this in context, see
The Notes red book has a lot of information on the Notes object model - see
Hope this helps

Mac
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top