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(Exists; @Do(@Command([OpenView];"(LookupView); Key); @Command([EditDocument]; "0"); @Command([OpenView]; "(LookupView)"); @Command([FileCloseWindow])); @Command([Compose]; Frm))