I’m trying to set “MonitorStatus” field equal to “ProjectStatus” field whenever the document is opened. It works for existing documents, but when I create a new document, I get an “Object variable not set” error. How do I correct this?
Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
You can’t use this code in QueryOpen though, as the FieldSetText method isn’t available at this point, so you’ll have to put this code in either PostOpen or OnLoad - both of which occur before the user gains control of the document.
The first line of code checks that the document is in edit mode before trying to set the value of the field, otherwise you will get a different error.
Subject: RE: Newbie needs help on queryopen script
Thanks for your quick response. I put this in Postopen as you suggested, but the field “MonitorStatus” is not being changed when I open an existing document. It works when I create a new document however.
What do I do so it works on both new and existing docs?
Subject: RE: Newbie needs help on queryopen script
The code I gave you will only work if the document is opened in edit mode, so perhaps using a combination of both of our techniques will work better. Try putting this as your QueryOpen:
if not IsNewDoc then
Set doc = source.Document
doc.MonitorStatus = doc.ProjectStatus(0)