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

I am trying to create a dialog box that contains a layout region for users to select a date (with the calendar). GRIEF!

I have a date field on my form that is named the same as a date field on the dialogboxform.

I have created a action (tried with button as well), on my form with the following LS.

Sub Click(Source As Button)

Dim workspace As New NotesUIWorkspace

Dim session As New NotesSession

Dim db As NotesDatabase

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set uidoc = workspace.CurrentDocument

Set doc = uidoc.Document

Call uidoc.RefreshHideFormulas()

flag = workspace.DialogBox( “dialogboxform” , True, True , False , False , False , False , “title” , doc, False , False , False )

This gives me the error “DialogBox cannot be used in this context; a document must be selected.”

I have looked at this thru debugger…Notes seems to have a handle on ‘doc’.

What am I missing?

I have searched thru the forum and have tried my declarations in the Global and PostOpen events…doesn’t seem to make a difference.

Subject: This is probably the ‘gotcha’

I had the same problem once, and it took me hours to find out that I had misspelled the form name in the dialogbox method.

So check out if the form “dialogboxform” realy exists and if it’s spelled correctly.

If the dialogbox method cannot find the form, it gives this dumb error message “DialogBox cannot be used in this context; a document must be selected.” wich has nothing to do with it.

Subject: RE: This is probably the ‘gotcha’

Years later this error message still has not changed…Thanks for your post and for google allowing me to find it :slight_smile:

Subject: I totally agree! Good old Google!

Subject: The gift that keeps on giving

And again this thread and Google come up trumps. Which means that this error message is still around in R8.5.1 !!Thanks.

Subject: …and giving

…still there in 8.5.3 FP2

Subject: Even in 2015 (a different reason)

Even in 2015 on Notes 9.0.1, the same obscure problem… I wanna die :frowning:

The reason I was having the error is that the dialog was linked to a timer event, and at the time the timer was triggering the user would be working on a different database, which didn’t have the dialog form…

Good luck, Notes gurus…

Subject: RE: This is probably the ‘gotcha’

After over three hours spent on this, I’m almost too embarassed to admit that yes, it was a spelling mistake!Thanks for making me recheck!!!

Subject: RE: This is probably the ‘gotcha’

11 years later this thread saved me from more than a few minutes of WTF headscratching. In my case, the “misspelling” was actually an extra space in front of the form alias, which was an artifact of dutifully copying the alias from the form design.

Thank you everyone on behalf of the future :-).

Subject: Another Gotcha solution

Yes, another reason this message appears, the form you are trying to use for the Dialogbox doesn’t exist!

I copied an agent that ran this piece of LS to another database, and forgot to copy it’s corresponding form for the dialogbox.

Doh. Reading the other gotcha solved my issue though. Cool.

Subject: RE: Another Gotcha solution

Thank You guys… That was so stupid of me to have a wrong form name !

I admit it.

Subject: I give you another Gotcha solution

In @Dialogbox you can specify a subform name. If you do the same in LotusScript it will say the same error message.

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

FYI, I also encountered this error message when trying to specify the form name using the alias instead of the full name. Replaced the alias with the full name in my code and the problem went away immediately. HTH.

Subject: This message appear when you have miss spelled form name

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

I have exactly the same trouble.Using the formname instead the alias solves the problem…

ARGHHHH!!!

Thank you a million for this tip!!

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

FWIW, testing on Win32 / Notes 6,02CF1, that code works just fine in a hotspot button on a form. So the error must occur elsewhere. No idea if that helps.

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

Thanks for the original post, saved me hours on a spelling error.