Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Opening Lotus Notes to create an email with an attachment


Message #1 by "Tammy Tappan" <GRTappan@e...> on Wed, 16 Jan 2002 23:18:04
Okay, I think I see the code I need for the email part; what I can't find 

for sure is the code for calling Lotus - what goes in the dim statement? 

Also, from Tools>References, am I just selecting Lotus Notes Automation 

Classes, or do I also/just need Lotus Domino Objects?



Right now I only have Lotus Notes Automation Classes chosen; when I write 

the stmt:



dim objLotus as - the list that comes up has a bunch of NOTESXXXXX types 

to choose from; if I try: dim objLotus as New - the list that comes up has 

nothing that looks like Lotus or Notes.



Any suggestions? As an aside, the folks that will be using this have their 

Lotus email program open probably 99% of the time, so I don't know that I 

need to "open" Lotus, just go to it?



+Tammy
Message #2 by "Alan Douglas" <aland@a...> on Sun, 20 Jan 2002 02:42:31
> Okay, I think I see the code I need for the email part; what I can't 

find 

> for sure is the code for calling Lotus - what goes in the dim statement? 

> Also, from Tools>References, am I just selecting Lotus Notes Automation 

> Classes, or do I also/just need Lotus Domino Objects?

> 

> Right now I only have Lotus Notes Automation Classes chosen; when I 

write 

> the stmt:

> 

> dim objLotus as - the list that comes up has a bunch of NOTESXXXXX types 

> to choose from; if I try: dim objLotus as New - the list that comes up 

has 

> nothing that looks like Lotus or Notes.

> 

> Any suggestions? As an aside, the folks that will be using this have 

their 

> Lotus email program open probably 99% of the time, so I don't know that 

I 

> need to "open" Lotus, just go to it?

> 

> +Tammy





Here's a module I used to open, send and clean up Lotus Notes ... maybe 

you can draw what you need from it.

... AL





Option Compare Database

Option Explicit



    Dim NotesSession As Object

    Dim NotesDB As Object

    Dim NotesMailDoc As Object

    Dim NotesRTF As Object

    Dim NotesDocID As String

    Dim Attachment As Object

    Dim EmbedObject As Object

    

    Const EMBED_FILE = 1454

    

Function OpenNotes() As Boolean



    On Error GoTo Err_OpenNotes

        

    Set NotesSession = GetObject("", "Notes.NotesSession")

    MsgBox "Start Lotus Notes & press the <OK> button when Lotus Notes is 

fully open ...", vbOKOnly, "OpenNotes()"

    ''' If the preceding "stall" is not inserted, you're 90% guaranteed to 

bomb ... Lotus Notes is really slow to open!

    

    Set NotesDB = NotesSession.GETDATABASE("", "") ' Default Database



    If Not NotesDB.ISOPEN Then

        Call NotesDB.OpenMail ' Open Lotus Notes Mail

    End If

    

    ''' THE FOLLOWING LOOP IS TOO PARTICULAR TO MY OWN APPLICATION ...

    '''Do While Not fIsAppRunning("Alan Douglas - Inbox - Lotus Notes 

Desktop")

    '''    DoEvents

    '''Loop

        

    OpenNotes = True

    

Exit_OpenNotes:

    On Error Resume Next

    Exit Function

    

Err_OpenNotes:

    OpenNotes = False

    MsgBox "Error: " & Err.Number & " -- " & Err.Description, 

vbOKOnly, "OpenNotes() Error"

    Resume Exit_OpenNotes



End Function

Function SendNotes( _

            sTo As String, _

            Optional sCC As String, _

            Optional sBCC As String, _

            Optional sSubject As String, _

            Optional sComments As String, _

            Optional sFileName As String) _

         As Boolean



    On Error GoTo Err_SendNotes



    Set NotesMailDoc = NotesDB.CREATEDOCUMENT

    NotesMailDoc.Form = "Memo"

    NotesMailDoc.FROM = NotesSession.COMMONUSERNAME

    NotesMailDoc.SendTo = sTo

    NotesMailDoc.SAVEMESSAGEONSEND = True

    If Not IsNull(sCC) And sCC <> "" Then NotesMailDoc.CopyTo = sCC

    If Not IsNull(sBCC) And sBCC <> "" Then NotesMailDoc.BlindCopyTo = sBCC

    If Not IsNull(sSubject) And sSubject <> "" Then NotesMailDoc.Subject = 

sSubject

    If Not IsNull(sComments) And sComments <> "" Then NotesMailDoc.Body = 

sComments



    If Not IsNull(sFileName) And sFileName <> "" Then

        Set Attachment = NotesMailDoc.CREATERICHTEXTITEM("Attachment")

        Set EmbedObject = Attachment.EmbedObject(EMBED_FILE, "", 

sFileName, "Attachment")

        'NotesMailDoc.CREATERICHTEXTITEM ("Attachment")     ''' not 

required in this version

    End If



    NotesMailDoc.SEND False     ''' False = don't edit it before sending

    

    SendNotes = True   ''' mail was successfully sent



Exit_SendNotes:

    On Error Resume Next

    Exit Function



Err_SendNotes:

    SendNotes = False

    MsgBox "Error: " & Err.Number & " -- " & Err.Description, 

vbOKOnly, "SendNotes() Error"

    Resume Exit_SendNotes



End Function



Sub CloseNotes()



    On Error Resume Next



' Cleanup objects, but leave Lotus Notes running ...



    Set NotesRTF = Nothing

    Set NotesMailDoc = Nothing

    Set NotesDB = Nothing

    Set NotesSession = Nothing

    Set Attachment = Nothing

    Set EmbedObject = Nothing

    

End Sub


  Return to Index