Open new Notes email from MS Access VBA

Sorry to proliferate this subject! However the code I have found either sends the new message automatically saving it to Sent items, or doesn’t send and saves it to Drafts.

What my users required is that the new message is composed from their MS Access application (with recipients, subject, and default text) and opened in it’s own window for editing before the user sends it manually.

I attach my code below and should be grateful for any help and advice on how it should be adapted to leave the message open. Also, it would be helpful if you could explain how this works as I do not seem to need to set any special references (under Tools/References in the VBA window), but yet it compiles with no problems. I’m using Access 2003 and Windows XP pro.

Thanks in anticipation

Richard

Code:

Option Compare Database

Option Explicit

Public Sub SendNotesMail(Subject As String, attachment As String, recipient As String, bodytext As String, saveit As Boolean)

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)



Set session = CreateObject("Notes.NotesSession")

’ session.Initialize ’ (“password”) ’ Not required when Notes is already running

UserName = session.UserName

MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"



Set Maildb = session.GetDatabase("", MailDbName)



If Maildb.IsOpen = True Then

     'Already open for mail

Else

    Maildb.OPENMAIL

End If



Set MailDoc = Maildb.CREATEDOCUMENT

MailDoc.Form = "Memo"

MailDoc.SendTo = recipient

MailDoc.Subject = Subject

MailDoc.body = bodytext

MailDoc.SAVEMESSAGEONSEND = saveit



If attachment <> "" Then

    Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")

    Set EmbedObj = AttachME.EmbedObject(1454, "", attachment, "Attachment")

    MailDoc.CREATERICHTEXTITEM ("Attachment")

End If



'Save the message to the Draft folder:

MailDoc.Save True, True

‘’ 'Send the document (DON’T WANT TO SEND IT, JUST OPEN IT FOR EDITING)

‘’ MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder

‘’ MailDoc.SEND 0, Recipient

'Clean Up

Set Maildb = Nothing

Set MailDoc = Nothing

Set AttachME = Nothing

Set session = Nothing

Set EmbedObj = Nothing

End Sub

Subject: Open new Notes email from MS Access VBA

OK - Going back to my original question, I reckon I’m pretty well committed to using the Notes backend classes / COM features of Notes as I have the code (referred to in the last thread) that almost does the job. I probably need just one line to open the message that was just saved to drafts in the line:

MailDoc.Save True, True

Does anyone know the code simply to open the message for the user to check and if necessary edit before sending manually?

Thanks again

Rick

Subject: RE: Open new Notes email from MS Access VBA

Would you believe that opening the document to the UI requires the UI (front-end) classes?

Subject: You’re using the Notes backend classes (which have no UI), you want to use the NotesUIWorkspace classes.

Basically you’re using the COM features of the Notes client versus the OLE automation features.

If you look in Domino Designer for OLE Automation (Using OLE) you will find an example and and explanation of UI workspace versus NotesSession

=-=-=-=-=-

This example represents a command button on a Visual Basic form. The button launches Notes if it is not already running, and then opens test4.nsf in the local data directory.

Private Sub Command3_Click()
Dim ws As Object
Set ws = CreateObject(“Notes.NotesUIWorkspace”)
Call ws.OpenDatabase(“”, “test4.nsf”)
End Sub

Subject: VBA Automation using COM features of the Notes client

OK, but the method I am using is practically complete. If I use your recommended method of OLE automation I will either need to install Notes/Domino on my development PC (I’m a contractor working from home), or will need to download a copy of the dll file I presume (and then I’ll be starting from scratch).

I am maybe just one line short of what I need to open the composed email message with the code I have already posted. Can you tell me what this is or where to find it?

Subject: RE: VBA Automation using COM features of the Notes client

" If I use your recommended method of OLE automation I will either need to install Notes/Domino on my development PC"

You’ll need that no matter what. Notes OLE Automation, backed or frontend classes require the Notes client. It also requires a Notes license and Notes ID. Notes OLE automation isn’t just a single DLL you can just ship with your application.