Make a lotus notes email visible after vba compilation so it can be manually edited and sent by the user

Hi Lotus experts!

Using the MS Outlook object model it's possible to display a precompiled email by setting the MailItem's visible property to True, so the user can then preview the email and edit it before manual desptach

I'm trying to achieve the same thing in for notes.  Is this possible ?  Here's my code below

Function fcnSendEmailByLotusNotes(strTo As String, strTitle As String, strBody As String, Optional strAttach As String = vbNullString)
'**********************************************************************************************************
' Author:                       JG
' Purpose:                     Send an email by Lotus Notes
' Date Written:              16/May/2006
' Amendment History:     <None>
'**********************************************************************************************************
 
'Declare Variables
Dim notesdb As Object
Dim notesdoc As Object
Dim notesrtf As Object
Dim notessession As Object
 
 Const EMBED_ATTACHMENT = 1454

On Error GoTo Err_fcnSendEmailByLotusNotes

   

    'Define Variables
        Set notessession = CreateObject("Notes.Notessession")
        Set notesdb = notessession.getdatabase("", "")

    'Open Email
        Call notesdb.openmail

    'Build Email
        Set notesdoc = notesdb.createdocument
        Call notesdoc.replaceitemvalue("Sendto", strTo)
        Call notesdoc.replaceitemvalue("Subject", strTitle)
        Set notesrtf = notesdoc.createrichtextitem("body")
        Call notesrtf.appendtext(strBody)
        Call notesrtf.addnewline(2)
       
        'Attach attachment
        If strAttach <> vbNullString Then
            notesrtf.EmbedObject EMBED_ATTACHMENT, "", strAttach
        End If

       
        'Call notesdoc.Send(False)
        notesdoc.Visible = True      '<----- This line doesn't appear to do anything!! How can I make notes display the email ???

    'End Notes Session
        Set notessession = Nothing

Exit_fcnSendEmailByLotusNotes:
    Exit Function

Err_fcnSendEmailByLotusNotes:
    MsgBox Err.Description
    Resume Exit_fcnSendEmailByLotusNotes

End Function



LVL 17
NatchiketAsked:
Who is Participating?
 
Sjef BosmanConnect With a Mentor Groupware ConsultantCommented:
That's not a small fly... More like a condor. I think it'll be very difficult, if not impossible. Actually, the document must be saved in order to get the rich-text field updated. So, if you don't mind saving the document before it is mailed...
    notesdoc.Save True, False
    ws.EditDocument True, notesdoc, True
0
 
Sjef BosmanGroupware ConsultantCommented:
To make the mail visible, Notes will have to be loaded completely and I suppose you don't intend to do that. In any case, Notes needs to know the form to use to display the mail, so you need to tell that:
        Call notesdoc.replaceitemvalue("Form", "Memo")

If you want to start Notes, use the EditDocument-method of NotesUIWorkspace to display the document:
    Dim ws As New NotesUIWorkspace ' if that works from COM...
    ws.EditDocument False, notesdoc, True
0
 
NatchiketAuthor Commented:
OK yes notes is already running

I inserted the line

Call notesdoc.replaceitemvalue("Form", "Memo")

but nothing happened
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Sjef BosmanGroupware ConsultantCommented:
And the other two lines?
0
 
NatchiketAuthor Commented:
I get 'Invalid use of New Keyword'  for the line
Dim ws As New NotesUIWorkspace

When i tried

Dim ws As NotesUIWorkspace
....
Set ws = New NotesUIWorkspace

Same error again

But notes is already running so do I need to instantiate a new workspace ?
0
 
Sjef BosmanGroupware ConsultantCommented:
Yes, you would have to instantiate it, but 1) it is not a new workspace, and 2) "This class is not supported in COM." according to the Help...

Set ws = CreateObject("Notes.NotesUIWorkspace")
0
 
NatchiketAuthor Commented:
Great thanks sjef_bosman, just one small fly in the ointment: the body text is missing, any idea how I can bring it back? Here is the code as it stands

Function fcnSendEmailByLotusNotes(strTo As String, strTitle As String, strBody As String, Optional strAttach As String = vbNullString)
'**********************************************************************************************************
' Author:                       JG
' Purpose:                     Send an email by Lotus Notes
' Date Written:              16/May/2006
' Amendment History:     <None>
'**********************************************************************************************************
 
'Declare Variables
Dim notesdb As Object
Dim notesdoc As Object
Dim notesrtf As Object
Dim notessession As Object
Dim ws As Object

 
 Const EMBED_ATTACHMENT = 1454

On Error GoTo Err_fcnSendEmailByLotusNotes

   

    'Define Variables
        Set notessession = CreateObject("Notes.Notessession")
        Set notesdb = notessession.getdatabase("", "")

    'Open Email
        Call notesdb.openmail

    'Build Email
        Set notesdoc = notesdb.createdocument
        Call notesdoc.replaceitemvalue("Sendto", strTo)
        Call notesdoc.replaceitemvalue("Subject", strTitle)
        Set notesrtf = notesdoc.createrichtextitem("body")
        Call notesrtf.appendtext(strBody)
        Call notesrtf.addnewline(2)
       
        'Attach attachment
        If strAttach <> vbNullString Then
             Call notesrtf.addnewline(2)
             notesrtf.EmbedObject EMBED_ATTACHMENT, "", strAttach
        End If

       
       Set ws = CreateObject("Notes.NotesUIWorkspace")
        ws.EDITDOCUMENT True, notesdoc, True


    'End Notes Session
        Set notessession = Nothing

Exit_fcnSendEmailByLotusNotes:
    Exit Function

Err_fcnSendEmailByLotusNotes:
    MsgBox Err.Description
    Resume Exit_fcnSendEmailByLotusNotes

End Function


0
 
NatchiketAuthor Commented:
Thanks for your generous help!
0
 
Sjef BosmanGroupware ConsultantCommented:
But be careful: the user might not be too happy with mails in his mail database that have never been sent. Please check where these mails pop up, you might need to set additional fields in order to prevent it to be displayed in certain views or folders.
0
 
marilyngCommented:
Just a note, you have to set the field ExcludeFromView to "A" or "D" so that you don't end up with 5,000 drafts.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.