Need a little help with this code

I’m opening a modal form to load a document from an embedded view.

When the user clicks on the OK button it saves the changes to the doc (inside the modal screen) and then return to the documnet with the embedded view. So far no probs…

but if i want the code inside the button that saves the modal doc to ALSO change the values of a few fields in the document with the embedded view I keep getting ‘object variable not set’ every time i try referencing doc.field1. I tried re’setting the doc, uidoc. ws, db, everything! but i keep getting the same error.

Is there a work around? Is there a way of getting a ‘hold’ of the document with the embedded view that was the parent (source) of the document that is currently opened in the modal screen?

Let me know if I’m not explaining this properly.

Below is the code inside the button of the modal form:

Dim db As NotesDatabase

Dim session As New NotesSession

Dim doc As notesdocument

Dim uidoc As notesuidocument

Dim ws As NotesUIWorkspace



Set db = session.currentdatabase

Set ws = New NotesUIWorkspace 

Set uidoc = ws.Currentdocument 

Set doc = uidoc.document



doc.SaveOptions = "1"		

Call uidoc.Save

'this saves the document in side the modal form	

	

call uidoc.close

'closes the modal form



Set db = session.currentdatabase

Set ws = New NotesUIWorkspace

Set uidoc = ws.Currentdocument  

Set doc = uidoc.document

'whethere i re-set these things or not i still get an 'object variable not set' on the next line



doc.Field1 = "12345" 'this is where i get 'object variable not set'

Thanks

ST

Subject: Need a little help with this code.

Hello,

Try switching on the debugger and step into each line of code one after the other and check for each of the objects… whether they are getting set properly.

It seems that the doc is not getting set properly.

Probably a glance at the doc object in the debugger should provide a better detail on the actual problem.

Regards,

Nitin

Subject: RE: Need a little help with this code.

Thanks for your suggestion Nitin, unfortuneately the debugger does not work once a modal screen is called.

Any other ideas?

ST

Subject: Need a little help with this code.

When you’re calling a modal dialog box, there are actually two UIDocument handles available.

NotesUIWorkspace.CurrentDocument returns the UI doc of the underlying document from which the dialog box was triggered.

PostOpen (Source as NotesUIDocument) on the form which the dialog box calls returns the UI doc represented inside the dialog.

You’ll need both of these to accomplish what you want. Just remember the difference, and you should be able to put all your code in the QueryClose event of the dialog’s form.

Subject: RE: Need a little help with this code.

Much appreciated Nathan. I was unware of this. I have not tried it yet but it sounds exactly like what I need.

Again thank you.

ST

Subject: RE: Need a little help with this code.

Sorry Nathan, I must be doing something wrong. I’m still getting “The NotesUIDocument object is no longer valid” when i put the code in the QueryClose event of the Modal Form (the form loaded inside the dialoguebox).

Maybe this bit of information will help. The parent form with the embedded view has this code in the queryopendocument event on the embedded view:

Sub Queryopendocument(Source As Notesuiview, Continue As Variant)

Dim ws As New notesuiworkspace

Dim col As notesdocumentcollection

Dim doc As notesdocument

continue = False

Set col = source.documents

Set doc = col.getfirstdocument

ws.DialogBox "(MyForm)", True, True, True, False, False, False, "Tital of Form", doc, True, True, False

End Sub

This opens the document in the embedded view within a DialogueBox.

I have my own OK Cancel buttons on this form.

When I Set the NotesUIWorkspace.CurrentDocument on the OK button of my DialogueBox form it is actually the uidoc of the DialogueBox and NOT the form with the embedded view.

Basically what I want: When the user clicks on The OK button it save the changes to the document within the DialogueBox. Once the changes are saved it CLOSES the dialogue box and returns to the form with the embedded view, however, 1 field on the form with the embedded view has taken the value of a field from the DialogueBox that was just saved.

I will refer to the form with the embedded view as the ParentForm and the Dilaogue Box form as DialogForm

Example:

ParentForm has a field called “Customer” and its value is “ABC Corp”. User opens a document using embedded view. The document is opened in a dialoguebox.

In DialogForm, the field “Customer” is also “ABC Corp.” but the user changes the value to “XYZ Corp.” and then saves the document. When the focus returns to the ParentForm I would like the “Customer” Field to change from “ABC Corp.” to “XYZ Corp.” as well.

The problem, as you know, is getting a handle of the ParentForm while having a handle of the DialogForm at the same time so that I can set these values as explained above.

Can you give me an example of code that I will need to use to get a handle of both and in which events (unless it can all be written in the OK button of the DialogForm).

Thanks Nathan.

ST

Subject: RE: Need a little help with this code.

Well, you might be stuck here. I’m not sure there’s a way to get the QueryOpenDocument event in an embedded view to be aware that it’s inside a document context. If you can do it, then it will be with the NotesUIWorkspace.currentDocument call BEFORE you call the dialog.

Now, if that works (I can’t test right this minute) then you set that before your dialog box call, then retrieve the value you need out of the dialoged doc after the ws.dialogbox call. You’ve already got the doc handle, so just read it out of there and write into the current doc.

If that doesn’t work, why not use an embedded editor instead of the dialog box? Then you won’t need a QueryOpenDocument event in the view at all. You can just drive it from the form for the document you selected in the embedded view.

Alternatively, you might be able to accomplish a bit more with the QueryOpen event on the target form. If you moved the dialog box call to there, instead of the view’s QueryOpen event, you might be able to find what you need.

Subject: RE: Need a little help with this code.

Thanks for your responses, Nathan and Nitin.

I will try your suggestions and post my results later today.

Thank-you

ST

Subject: RE: Need a little help with this code.

Not sure whether this will help or not but you can always give it a try… just in case.

I refer the child doc with the object “doc” as you are setting the object “doc” as the child document.

Let the parent_doc be the main parent doc from which the modal dialog is opened.

Now in the ws.dialogbox just check that whether the user has clicked on OK or cancel… using the return value… you can check the notes help for the return values.

Once you figure out that the OK button has been clicked… then just after the call to the dialogbox… write the code…

'>>>>

ws.currentDocument.Document.ReplaceItemValue(“Customer” , doc.GetItemValue(“Customer”)(0))

'>>>>

This is assuming that both the forms have the field names as Customer.

The point here is that you have the handle to both the documents here… that is the Parent_Doc as well as the Child_Doc.

Another assumption is that the changes made to the fields in the Child doc are being saved in the dialog box itself.

Hope this helps.

Regards,

Nitin