Lotus Notes FAQ Visit Our Sponsor!

How do you open a document in edit mode if it exists?

This example looks up a document and opens it in edit mode if it exists. Otherwise, it composes a new document.

"INFO" represents any fields that are required for inheritance to new docs. You need to do the validation in the button because validation formulas will not be executed when a button is pushed.

BailOut:=@If(INFO="";  @Return(@Prompt([OK];"INFO Required";
   "Please enter INFO before proceeding."));"");

You can use a number of other BailOut statements to check for other required items. When opening multiple windows it's usually wise to save. It is also required to save in case the lookup fails and you need to create a response.
Remember that this will trigger all translation and validation formulas:

Save:=@If(@IsNewDoc;@Command([FileSave]);"");

"KeyStuff" is used to identify a particular document.

Key:=@Text(@DocumentUniqueID)+KeyStuff;

"DATA" is whatever you are looking up. In this case it is used to verify that what you're looking for exists.

Doc:=@DbLookup("":"NoCache";"";"(LookupView)";Key;"DATA");
Exists:=@If(@IsError(Doc);@False;@IsMember(KeyStuff;Doc));

If you found the right doc:
1) Open the view and go to the doc you found.
2) Put the doc in edit mode.
3) Switch back to the view window and close it.
Otherwise, compose a new one.

@If(Exists;
 @Do(@Command([OpenView];"(LookupView); Key); 
 @Command([EditDocument]; "0");
 @Command([OpenView]; "(LookupView)");
 @Command([FileCloseWindow]));
@Command([Compose]; Frm))

Applies to Notes Versions: 3
Last Modified: October 30, 1996