Lotus Notes - Object Variable Not Set error when email previewed

This is a follow up to this previous question:
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/Lotus_SmartSuite/Lotus_Notes/Q_25423932.html

I have the following script in the PostOpen event of a form sent to users:

Sub Postopen(Source As Notesuidocument)
 Dim workspace As New NotesUIWorkspace
 Dim uidoc As NotesUIDocument
 Dim redirectid As String
 Set uidoc = workspace.CurrentDocument
 redirectid = uidoc.FieldGetText( "DocID" )
 
 Source.Close      
 Dim ws As New NotesUIWorkspace
 Dim s As New NotesSession
 Dim db As NotesDatabase
 Set db = s.GetDatabase("servername", "databasename.nsf")
 Dim doc As notesdocument      
 Set doc = db.getDocumentByUNID(redirectid)      
 Call ws.EditDocument(False, doc, True)
End Sub

It does exactly what I need it to do except when users view their email in the preview pane.  If the preview pane is open, when they click on the email, an error message appears stating: "Object Variable not Set".  If the user then clicks to open the email, everything works fine.

How do I prevent this error?  Is there a way to determine whether the email is being previewed and then only run the PostOpen script when the email is actually opened rather than previewed?

Thanks!
rfoneillAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rfoneillAuthor Commented:
I've found one possible work around by adding the following at the top of the PostOpen script:

If source.InPreviewPane Then Exit Sub

Then, I can place a message in the source document telling users to open the email to view the newsletter.

This is not idea. If possible, I'd prefer to be able to set whatever object needs to be set and display the newsletter in the preview pane.

Please advise.
0
mbonaciCommented:
If you just want to avoid prompting an user with error message (everything works fine except error message) you can add this line at top of your code:

On Error 91 Resume Next

'91 is 'Object variable not set' error code
0
rfoneillAuthor Commented:
Thanks.

Unfortunately, if the person has the preview pane open, 'On Error 91 Resume Next' prompts another error:

'Invalid universal ID'

I'd prefer the newsletter actually display in the preview pane if at all possible.

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

mbonaciCommented:
You can try with:

    Call notesUIWorkspace.SetTargetFrame( frame$ )

just before EditDocument line.

Check out the name of the preview frame (I think it's NotesPreview, but I'm not sure) in your mail frameset.
0
Bill-HansonCommented:
There are a couple of things working against you here.

The first thing that jumps out at me is the mixed use of workspace.CurrentDocument and Source.  They are actually the same object, but using the one provided as an argument to PostOpen (Source) is the best practice.

Secondly, you are calling Source.Close (which will always fail when previewed).  This is where you need to check whether the document has been opened in the preview pane.  Use the NotesUIDocument.InPreviewPane property for this.

There are a couple of other problems here such as multiple declarations of NotesUIWorkspace and calling Source.Close before all code has executed, but it should work ok like this...
Sub Postopen(Source As Notesuidocument)
	
	Dim ws As New NotesUIWorkspace
	Dim session As New NotesSession
	Dim db As NotesDatabase
	Dim doc As notesdocument      
	Dim redirectid As String
	
	redirectid = Trim(Source.Document.GetItemValue("DocID")(0))
	If (redirectid = "") Then Error 1000, "Unable to locate DocID!"

	Set db = session.GetDatabase("servername", "databasename.nsf")
	If (db Is Nothing) Then Error 1000, "Unable to open database!"

	Set doc = db.getDocumentByUNID(redirectid)
	If (doic Is Nothing) Then Error 1000, "Unable to locate document!"

	Call ws.EditDocument(False, doc, True)
	If (Not Source.InPreviewPane) Then Call Source.Close(True)
	
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rfoneillAuthor Commented:
Bill-Hanson:  Thanks!  I tried the code and it works (there's just a minor typo - see 'doic'), almost too well.  When the email is highlighted with the preview pane open, the newsletter opens in a separate tab, taking the user away from the inbox.  My only concern with this is users who really like using the preview pane will be annoyed when they are taken away from their inbox.  Nevertheless, your code is much cleaner than mine.  So, I'm using it with the InPreviewPane at the top to exit sub if true.

mbonaci: Thanks as well! I have not tried setting the target frame yet but will and will let you know.
0
rfoneillAuthor Commented:
mbonaci: I have not been able to confirm the name of the frame for the preview pane in the MailFS.  I tried "NotesPreview" and "PreviewPane" but neither worked.
0
mbonaciCommented:
Open the frameset in designer and look.
0
rfoneillAuthor Commented:
It is called 'NotesPreview'.  I added the following to the script:

Call ws.SetTargetFrame("NotesPreview")

just above

Call ws.EditDocument(False, doc, True)

0
mbonaciCommented:
And it doesn't work? Too bad, sorry.
0
rfoneillAuthor Commented:
No, unfortunately it didn't work.  Thanks though.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.