Link to home
Start Free TrialLog in
Avatar of Juan Velasquez
Juan VelasquezFlag for United States of America

asked on

Sending query results to Lotus Notes from Access

Hello,

I have a query in a Access 2007 database, whose results I wish to send to lotus notes as an attachment.  I've verified that the lotus notes references are set.  I need some help in how to best export the query results to lotus notes.  There is a method called docmd.send object that I think I could use.  I would appreciate any help
Avatar of Juan Velasquez
Juan Velasquez
Flag of United States of America image

ASKER

I found the solution at http://www.fabalou.com/VBandVBA/lotusnotesmail.asp  I understand most of the code but am unsure of the following '.CreateRichTextItem ("Attachment" & CStr(intAttach))
I found I had to comment it out to make it work.
Public Sub SendNotesMail(Subject As String, Attachment As String, BodyText As String, SendTo As String, Optional CC As String = "", Optional BCC As String = "", Optional SaveIt As Boolean = False)
    '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)
    Dim intAttach As Integer
    
    'Start a session to notes
    Set Session = CreateObject("Notes.NotesSession")
    '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
    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
    With MailDoc
        .Form = "Memo"
        .SendTo = Split(SendTo, ",")
        .CopyTo = Split(CC, ",")
        .BlindCopyTo = Split(BCC, ",")
        .Subject = Subject
        .Body = BodyText
        .SaveMessageOnSend = SaveIt
    'Set up the embedded object and attachment and attach it
        Dim aryAttachment() As String
        aryAttachment = Split(Attachment, "|")
        For intAttach = LBound(aryAttachment) To UBound(aryAttachment)
            Set AttachME = .CreateRichTextItem("Attachment" & CStr(intAttach))
            Set EmbedObj = AttachME.EmbedObject(1454, "", aryAttachment(intAttach), "Attachment" & CStr(intAttach))
            
            '.CreateRichTextItem ("Attachment" & CStr(intAttach))
        Next intAttach
    'Send the document
        .PostedDate = Now() 'Gets the mail to appear in the sent items folder
        .Send False
    End With
    'Clean Up
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set Session = Nothing
    Set EmbedObj = Nothing
End Sub

Open in new window

Avatar of Sjef Bosman
There are hundreds of pages explaining how to send a mail through Notes, with an attachment. In most cases, the attachment has to be created first, as a file.

Here's an example:
- http://www.fabalou.com/VBandVBA/lotusnotesmail.asp
ASKER CERTIFIED SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial