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:
- It doesn't always open the right draft email for editing.
- 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.GetEnvironment开发者_如何学CString("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
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?
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)
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.)
精彩评论