Help With VBA code to create Lotus Notes E-Mail

I have an Access Database where I am trying to create a Lotus Notes e-mail from. The import factor here is that I do not want to send the e-mail, I just want Access to create it, attach an attachment and then display Lotus Notes so the user can then add any additional text they would like. The user then will have the hit send.

The code I have so far seems to be really close but I can not get over the last hurdle and was hoping someone could help me out.

Below is the code I have. Any suggestions are appreciated.

Dim session As NotesSession

Dim MailDb As NotesDatabase

Dim MailDoc As NotesDocument

Dim oAttachME As Domino.NotesRichTextItem

Dim oEmbedObj As Domino.NotesEmbeddedObject

Dim oNotesWS As NOTESUIWORKSPACE

Dim strAttachmentName As String

Dim uiws As Object

Dim uidoc As Object

'Purpose: Start a session to notes

        Set session = CreateObject("Lotus.NotesSession")

    

        Call session.Initialize(LotusPassword)

'Purpose: Open the mail database in Lotus Notes

        Set MailDb = session.GetDatabase(ServerName, MailFile)

        

        If MailDb.IsOpen = True Then

            'Already open for mail

        Else

            Call MailDb.Open

        End If

'Purpose: Set up the new mail document

        Set MailDoc = MailDb.CreateDocument

        

        strAttachmentName = ProPath & lstIssueAttachments.Column(1)

        

        Set oAttachME = MailDoc.CreateRichTextItem("Body")

        Set oEmbedObj = oAttachME.EmbedObject(1454, "", strAttachmentName)

        

        Call MailDoc.ReplaceItemValue("Form", "Memo")

‘So by this point I think I have successfully created the e-mail with an attachment but now I have to open Notes in edit mode so the user can view the attachment and add any extra text they would like. Basically, I am not sure about this next portion of code.

Set uiws = CreateObject(“Notes.NotesUIWorkspace”)

        Call uiws.EDITDOCUMENT(True, MailDoc) – Here is where I am getting my error.  Access tells me Run-Time Error 7419 – Incorrect argument type: Object Expected.

Like I said, any help or suggestions is appreciated.

Thanks

Darren

Subject: not supported in COM . . .

Hey Darren -

The NotesUIWorkspace class isn’t supported for use in COM – check Designer Help for details.

dgg

Subject: RE: not supported in COM . . .

Thank you for the response but I honestly do not know what you mean. I have been coding Access for over 5 years but only with Lotus Notes for about a month. What does not supported for use in COM mean? Do you know how I would do this instead of using NotesUIWorkspace?

Thanks again for the suggestion.

Subject: I don’t think that is your issue. You are using OLE, not COM

COM is a backend way to instantiate objects, but you are using a frontend way. You can certainly create an object for the NotesUIWorkspace the way you did. Take a look at the Using OLE Help topic in the Designer Help. It has one part that seems applicable:

OLE automation uses late binding. You cannot create new Domino objects as in LotusScript. You must create (for example, with CreateObject) a Notes.NotesUIWorkspace or Notes.NotesSession object and work down through the hierarchies using the available methods. For example, if you want to open a Domino back-end database, create a Notes.NotesSession OLE automation object, then use the GetDatabase method of NotesSession to set a reference variable.

In Visual Basic, declare the reference variables for all Domino objects as type Object. When you finish using a Domino object, set the reference variable to Nothing to free the memory it uses.

While that doesn’t completely answer your question, it gets you closer. I think your MailDoc and MailDB need to be declared as Object type and then be instantiated by using the GetDatabase method of the NotesSession class and then the CreateDocument method of the NotesDatabase class, and then populate the document and use it as the argument to the EditDocument call you made. This is one of those cases where the error actually means what it says " Incorrect argument type: Object Expected." and you need to give it a variable of type Object as described above.

Let me know if this isn’t clear.

Subject: RE: I don’t think that is your issue. You are using OLE, not COM

I apologize for not checking this yesterday because I would really like to get this to work. I had a work issue that came up that has more precedence so I had to take care of that.

I think I understand what you guys are saying. To be honest, I though anything I created was an object so that is why that message was confusing to me.

Below is what I changed but I am still getting the same error. Am I not changing something to an object that I should be?

Dim ProPath As String

Dim response As String

Dim session As Object

Dim MailDb As Object

Dim MailDoc As Object

Dim oAttachME As Object

Dim oEmbedObj As Object

Dim uiws As Object

Dim uidoc As Object

'Purpose: Start a session to notes

        Set session = CreateObject("Lotus.NotesSession")

    

        Call session.Initialize(LotusPassword)

'Purpose: Open the mail database in Lotus Notes

        Set MailDb = session.GetDatabase(ServerName, MailFile)

        

        If MailDb.IsOpen = True Then

            'Already open for mail

        Else

            Call MailDb.Open

        End If

'Purpose: Set up the new mail document

        Set MailDoc = MailDb.CreateDocument

        

        strAttachmentName = ProPath & lstIssueAttachments.Column(1)

        

        Set oAttachME = MailDoc.CreateRichTextItem("Body")

        Set oEmbedObj = oAttachME.EmbedObject(1454, "", strAttachmentName)

        

        Call MailDoc.ReplaceItemValue("Form", "Memo")

Set uiws = CreateObject(“Notes.NotesUIWorkspace”)

Call uiws.EDITDOCUMENT(True, MailDoc) – Access is still expecting an object. Run-time error ‘7419’: Incorrect argument type: object expected.

I do appreciate your time and knowledge.

Thanks

Darren

Subject: RE: I don’t think that is your issue. You are using OLE, not COM

I’m not sure that cross-talk between COM and OLE objects can happen like that – if you want to use the OLE Automation objects, then all of the object sources need to be in that “package”, so to speak. If you make your session object:

Set session = CreateObject(“Notes.NoteSession”)

then the session object and workspace object should be able to talk to one another.

Subject: RE: I don’t think that is your issue. You are using OLE, not COM

Instead of this:

Set session = CreateObject(“Lotus.NotesSession”)

try this:

Set session = CreateObject(“Notes.NotesSession”)

Subject: RE: I don’t think that is your issue. You are using OLE, not COM

I did try this but then the below code does not work.

Call session.Initialize(LotusPassword)

How do I then provide Lotus with my password?

Subject: RE: I don’t think that is your issue. You are using OLE, not COM

Sorry… I do not have Lotus Notes at home so I have to do everything from work. The exact error I am getting is Run-Time error ‘438’ Object does not support this property or method.

This occurs in the below code.

Dim session As Object

Dim LotusPassword as String

LotusPassword = “mypassword”

Set session = CreateObject(“Notes.NotesSession”)

Call session.Initialize(LotusPassword)

Any help would be greatly appreciated.

Thanks

Darren

Subject: RE: I don’t think that is your issue. You are using OLE, not COM

I just tried a hunch to see if it worked and it kind of did. I removed the Password call. The code then successfully created an e-mail in Lotus Notes with the attchment. I am really excited about this but I still want to make a few changes.

This code only works if Lotus Notes is open, which I was trying to get to work regardless of that. Also, the e-mail has a line inserted before the attachment.

Do you know if there is a way to add code so I can provide a password? Also, why is there a line in the e-mail?

Below is my code.

Dim ProPath As String

Dim response As String

   

Dim session As Object

Dim MailDb As Object

Dim MailDoc As Object

Dim oAttachME As Object

Dim oEmbedObj As Object



Dim strAttachmentName As String

   

Dim ServerName As String

Dim MailFile As String

Dim LotusPassword As String

   

Dim uiws As Object

Dim uidoc As Object

Set session = CreateObject(“Notes.NotesSession”)

Set MailDb = session.GetDatabase(ServerName, MailFile)

If MailDb.IsOpen = True Then

            'Already open for mail

        Else

            Call MailDb.Open

        End If

Set MailDoc = MailDb.CreateDocument

        strAttachmentName = ProPath & lstIssueAttachments.Column(1)

        

        Set oAttachME = MailDoc.CreateRichTextItem("Body")

        Set oEmbedObj = oAttachME.EmbedObject(1454, "", strAttachmentName)

        

        Call MailDoc.ReplaceItemValue("Form", "Memo")



        Set uiws = CreateObject("Notes.NotesUIWorkspace")



        Call uiws.EDITDOCUMENT(True, MailDoc)

Thanks

Darren

Subject: I think you’ve already figured this out but . . .

Darren -

Didn’t mean to abandon this thread – I’ve sort of been out of commission for a while. When I was looking over some of my other posts, I saw this.

I gathered that you were able to get it to work with Andre’s help, right? As I read over this thread however, I thought I’d offer one additional possibility. Since you can’t provide a password in OLE (as you may have already guessed), you could check to see if Notes is active. The only way I can think of to do that is to search for the " - Lotus Notes" window via Win32 API.

If Notes is active, bring up the newly composed document as you’ve already coded.

If Notes is not active, launch it (which would allow the user to enter their password), then bring up the newly composed document.

That might be unnecessarily complicated, but thought I’d offer it up as a possible solution.

dgg

Subject: RE: not supported in COM . . .

Darren -

Sorry for the incomplete response . . . glanced at your code and saw the way the first few Notes/Domino objects were declared without bothering to check the rest of it (thanks for correcting me Ben).

It looks like you’re using a combination of COM and OLE in the snippet that you posted. Specifically , you seem to be creating “MailDoc” as a COM object while “uiws” is created as an OLE object. Then you pass a NotesDocument COM object to the EditDocument method of a NotesUIWorkspace OLE object which, as Ben pointed out, expects an Object.

Fyi, if you check your project references (Alt+P), you should find the “Lotus Domino Objects” available - these are the COM objects. The OLE classes will be listed as “Lotus Notes Automation Classes”. If composing a mail memo is all you’re trying to do, you don’t really need the COM objects. Oh, and make sure to clean up (ie, set to “Nothing”) the OLE objects when you’re done with them.

hth,

dgg