DialogBox cannot be used in this context; a document must be selected

I have 2 dbs. The second db has an embedded view. The view is in the first db. The embedded view has two buttons. New and Edit. They both work great. The problem arises when you double click on the actual document in the view to edit it. The below is the code in the queryopen event of the document.

I get the “DialogBox cannot be used in this context; a document must be selected” error. I read somewhere on this forum that maybe it couldn’t find the form ( in my case subform )so I copied it into the second db. I still get the error. Any ideas?

Thks,

jamie

Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)

Continue = False

Dim ws As New NotesUIWorkspace





Call ws.DialogBox( "Contact View", True, True, True, False, True, False, "Contact Report - READ ONLY:" )

End Sub

Subject: DialogBox cannot be used in this context; a document must be selected …

This misleading error message caught me out again.

Check for typo on 1st parameter Form Name.

The subform named must exist in current database.

I typed Metting instead of Meeting.

Subject: DialogBox cannot be used in this context; a document must be selected …

Well, don’t use ws.DialogBox in the form’s QueryOpen event.

Subject: RE: DialogBox cannot be used in this context; a document must be selected …

Uhh, thanks for the insight Lawrence, but it is a legacy app and I really don’t want to spend any more time on it than I have to.

Anybody else have any ideas?

Here is a little bit more information about the problem. When I turn on the debugger and go into the form and then double click on the document in the embedded view, I can walk through with debugger and then the subform/dialog box will actually pop up except that all the fields are blank. None of the date from the document displays. Weird. Is this a bug?

All feedback appreciated.

Thks

Subject: RE: DialogBox cannot be used in this context; a document must be selected …

Jamie,

I’ve often had similar error msgs with dialog boxes where there is no direct handle to a document and one workaround is to create a dummy container document in the script (dummydoc).

Add the fields to the dummy doc that you want to see, dummydoc.field1 = xyz, dummydoc.field2 = 123 etc,

Use dummyDoc in the dialog. flag = notesUIWorkspace.DialogBox( form$ , [autoHorzFit] , [autoVertFit] , [noCancel] , [noNewFields] , [noFieldUpdate] , [readOnly] , [title$] , DUMMYDOC , [sizeToTable] , [noOkCancel] , [okCancelAtBottom] ) not the currently selected document.

Then process the dummydoc data as needed depending after the user presses, OK, cancel or whatever.

In extreme cases I’ve got a handles on multiple source documents from different databases, created a dummydoc with all the required fields, used the dummydoc in a dialog box then copied the updated fields as needed back to the source documents which are then saved.

The Form used to display the data must be in the current database where the code is being run, not the just the source database the one where the document is located.

Subject: RE: DialogBox cannot be used in this context; a document must be selected …

Beautiful. Thank you AJP FilmIT.

I’d still like to know why the orginal wasn’t working, but that will have to wait for another day.

  • jamie

Subject: RE: DialogBox cannot be used in this context; a document must be selected …

I get the same error when the the Subform used in the dialogbox doesn’t exist.

I had a typo in the script and this misleading error sent me on a short wild goose chase.

Subject: Thanks Brian!!!

You just saved my night.My particular wild goose chase hasn’t been precisely short :frowning:

Thanks again