views:

86

answers:

3

This function was written to create a Lotus email, populate it, save it to the Drafts section, and then open it for the user to edit. However, it has 2 problems:

  1. It doesn't always open the right draft email for editing.
  2. It sometimes produces a "Notes Error - Specified command is not available from the workspace." error message. (The email is still saved, so it's no big loss).

Both problems occur at irregular intervals. If there's a pattern, I haven't seen it yet. Can I make these problems go away? Any other tips on reducing errors here?

(Note: I'm leaving out the error handler)

Dim NtSession As New NotesSession
Dim NtDB As New NotesDatabase
Dim NtWkSp As Object
Dim NtDoc As New NotesDocument
Dim NtObj As New NotesEmbeddedObject
Dim NtBodyRT As New NotesRichTextItem
NtSession.Initialize

'==========================================================================
'Open the mail server
Set NtDB = NtSession.GetDatabase( _
    NtSession.GetEnvironmentString("MailServer", True), _
    NtSession.GetEnvironmentString("MailFile", True), _
    True)

'==========================================================================
'Fill in basic email fields
Set NtDoc = NtDB.CreateDocument
NtDoc.AppendItemValue "Form", "Memo"
Set NtBodyRT = NtDoc.CreateRichTextItem("Body")
AddFields

'=========================================================================
' Save it to the drafts folder
DoEvents
NtDoc.SaveMessageOnSend = True
NtDoc.SignOnSend = True
NtDoc.Save False, False, True
Set NtWkSp = CreateObject("Notes.NotesUIWorkspace")
DoEvents
NtWkSp.OpenDatabase _
    NtSession.GetEnvironmentString("MailServer", True), _
    NtSession.GetEnvironmentString("MailFile", True), _
    "($Drafts)"
DoEvents
NtWkSp.VIEWREFRESH
NtWkSp.EDITDOCUMENT

Set NtWkSp = Nothing
Set NtSession = Nothing
A: 

after the NtWkSp.VIEWREFRESH call you will need to make sure the View selection is on the draft you just added, otherwise, when you call NtWkSp.EDITDOCUMENT it will always open the first draft, since thats where the View it pointing.

Other than that it seems strange that you would use Early Binding for the Domino Objects, and Late Binding for the Lotus Automation Classes, but maybe there is a purpose?

What line does the Notes Error occur on?

Fink
I don't know where exactly the error occurs since it's difficult to reproduce during normal work hours.
PowerUser
To answer your Early vs Late Binding question, I don't remember anymore the original reason. But it works (most of the reason). If you think I should just late bind everything, I can do that too.
PowerUser
It will still work, just a bit confusing.
Fink
Unfortunately, as I said to Ed, `NtWkSP.EditDocument (true, NtDoc) ` returns an "Incorrect Argument Type: Object Expected" error. I tried several different variations of this, but couldn't get anywhere.
PowerUser
A: 

The NotesUIWorkspace EditDocument method optionally can be passed a handle to a Notes Document, and will open that document in edit mode. So, you could use something like:

...
NtWkSP.EditDocument (true, NtDoc)
Ed Schembor
I'm adding those params to my EditDocument line, but I keep getting "Object Expected" errors. What else can I do?
PowerUser
I'm not sure if VBA cares, but EditDocument returns a NotesUIDocument object, so you may need to do something like: set uidoc = NtWkSP.EditDocument(true, NtDoc) or call NtWkSP.EditDocument(true, NtDoc)
Ed Schembor
Arg. Tried both ideas and I'm still getting the same Object Expected error. I've never figured out how the Lotus API works, so any more suggestions are welcome.
PowerUser
A: 

The two sets of classes are unrelated and use different APIs and different runtime contexts -- your NtDoc object will not exist in the workspace context. As much as I hate to do so, I'd suggest doing the whole thing in the Notes Automation classes. You'd have to open a NotesSession in the Notes namespace anyway in order to make sure you have the right document (whether using NotesDatabase.GetDocumentByUNID, NotesDatabase.GetDocumentByID or NotesView.GetDocumentByKey). Obviously having two sessions, two databases, two documents, et cetera, all pointing to different handles to the same set of objects is going to get messy and may actually cause collisions along the way.

(And to answer an earlier question, the Lotus Domino Objects are a supported COM interface that supports early binding but only has access to the back end; the Notes Automation Objects interface is an earlier and deprecated OLE interface that does not support early binding and is, frankly, kind of crashy.)

Stan Rogers