Newbie needs help on queryopen script

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)

Set doc = source.Document

doc.MonitorStatus = doc.ProjectStatus(0)

End Sub

Subject: Newbie needs help on queryopen script

The QueryOpen event Occurs just before the current document is opened and is Read-only.

Try PostOpen.

Subject: Newbie needs help on queryopen script

HI,

The NotesDocument property of a NotesUIDocument doesn’t exist when the UIDocument is brand new, so your ‘doc’ variable doesn’t get set.

Try using the following code instead:

If source.EditMode then

Call source.FieldSetText("MonitorStatus", source.FieldGetText("ProjectStatus"))

End if

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.

Emily.

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)

End if

And this as your PostOpen (or OnLoad)

If source.IsNewDoc and source.EditMode then

Call source.FieldSetText(“MonitorStatus”, source.FieldGetText(“ProjectStatus”))

End if

Let me know how you get on!

Emily.

Subject: RE: Newbie needs help on queryopen script

Thanks. I’ll try that. I could also make it work by automically having the form open in edit mode, but I’d rather not.

Subject: RE: Newbie needs help on queryopen script

Emily…you are the best. Works perfectly. You saved me a bunch of time today!