NotesUIDocument object is no longer valid in Modal DialogBox

I have a modal dialog box called on a document in an embedded view from the view’s Queryopendocument:

Call workspace.DialogBox (“StatusEntry”, True, True, True, True, False, False, “New Status Entry”, doc, True,True,True)

I am trying to create a warning if the user makes changes in the dialog box and tries to leave without clicking Save. I need to prevent them from clicking Close (without Saving) or hitting Escape, so I use the Queryclose event like this:

Close button


Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Set uidoc = ws.CurrentDocument

uidoc.close

Queryclose


Dim ws As New NotesUIWorkspace

‘Note: wasChanged is set in fields’ onChange event to True, else it’s False.

If wasChanged Then

If ws.Prompt(PROMPT_YESNO, “Close without Saving?”, “”) = 0 Then

Continue = False

End If

End If

If the user clicks “Close”, then changes their mind and clicks “No” in the Prompt box, then changes their mind back and clicks “Close” again, I get the message NotesUIDocument object is no longer valid

How could that possibly be? I get the same problem if I make uidoc global and set it in the form’s Postopen event with Set uidoc = Source.

What could be wrong here?

Thanks,

-Jeff

Subject: NotesUIDocument object is no longer valid in Modal DialogBox

Try using an Exit Sub immediately after your continue=false. I’m thinking if it exits prematurely (along with continue=false), notes won’t ‘unload’ the modal document

continue=false seems to work in strange ways sometimes. I think in your case, it is stopping the QueryClose event, but not the OnUnload event which occurs just after QueryClose.

It seems that even though the uidoc is not closed, it is unloaded from memory. (how it still stays on the screen is beyond me).

Here’s a quote from Designer Help:

“If backward compatibility is not an issue, OnUnload (introduced in Release 6) is preferred. QueryClose occurs before OnUnload if both are used.”

It may also be a caching issue. But this usually seems to happen in database script events. Sounds silly, but close everything and remove and replace the ws icon to be sure it’s not an caching problem.

Good luck

Subject: RE: NotesUIDocument object is no longer valid in Modal DialogBox

Try using an Exit Sub immediately after your continue=false.

This did not work. Apparently it is still unloading the uidoc from memory.

I also tried adding the same code (below) to Onunload, but still received the same error when I clicked the Close button a second time:

Sub Onunload(Source As Notesuidocument, Continue As Variant)

Dim ws As New NotesUIWorkspace

If wasChanged Then

	If ws.Prompt(PROMPT_YESNO, "Close without Saving?", "") = 0 Then

		Continue = False

		Exit Sub

	End If

End If

End Sub

It may also be a caching issue. But this usually seems to

happen in database script events. Sounds silly, but close

everything and remove and replace the ws icon to be sure

it’s not an caching problem.

What is the “ws icon”? I use the workspace as my home page. I don’t know how to do what you describe.

Thanks for the help,

-Jeff

Subject: RE: NotesUIDocument object is no longer valid in Modal DialogBox

i mean the workspace icon. right click it and “remove from Workspace”, then open the db again and see if it works.

That worked for me a few times when my continue=false wasn’t working.

Subject: RE: NotesUIDocument object is no longer valid in Modal DialogBox

I can’t find a Workspace icon anywhere on my Workspace. Can you give more direction?-Jeff