This code is based on 3 edit fields being populated or not (adds 1 to 3 forms, in reverse order after the current form so they appear in order)(also sets a hidden field to signify the form has already been loaded):
{/* load forms based on periods in protocol */}
{if gblPeriod2=="" then
if DOCUMENT.FORM_2<>"" then
REMOVE_FORM_COMP("Oncology Chemo Orders 2 PP")
REMOVE_FORM_COMP("Oncology Chemo Orders 2 TS")
DOCUMENT.FORM_2 = ""
endif
else
if DOCUMENT.FORM_2=="" then
AddOpenForm("Enterprise\Hematology&Oncology^Oncology Chemo Orders 2 TS", "Oncology Chemo Orders 1 TS", "AFTER_CURRENT", "")
AddOpenForm("Enterprise\Hematology&Oncology^Oncology Chemo Orders 2 PP", "Oncology Chemo Orders 1 TS", "AFTER_CURRENT", "")
DOCUMENT.FORM_2 = "added"
endif
endif}
{if gblPeriod3=="" then
if DOCUMENT.FORM_3<>"" then
REMOVE_FORM_COMP("Oncology Chemo Orders 3 PP")
REMOVE_FORM_COMP("Oncology Chemo Orders 3 TS")
DOCUMENT.FORM_3 = ""
endif
else
if DOCUMENT.FORM_3=="" then
if DOCUMENT.FORM_2<>"" then
REMOVE_FORM_COMP("Oncology Chemo Orders 2 PP")
REMOVE_FORM_COMP("Oncology Chemo Orders 2 TS")
endif
AddOpenForm("Enterprise\Hematology&Oncology^Oncology Chemo Orders 3 TS", "Oncology Chemo Orders 1 TS", "AFTER_CURRENT", "")
AddOpenForm("Enterprise\Hematology&Oncology^Oncology Chemo Orders 3 PP", "Oncology Chemo Orders 1 TS", "AFTER_CURRENT", "")
DOCUMENT.FORM_3 = "added"
AddOpenForm("Enterprise\Hematology&Oncology^Oncology Chemo Orders 2 TS", "Oncology Chemo Orders 1 TS", "AFTER_CURRENT", "")
AddOpenForm("Enterprise\Hematology&Oncology^Oncology Chemo Orders 2 PP", "Oncology Chemo Orders 1 TS", "AFTER_CURRENT", "")
DOCUMENT.FORM_2 = "added"
endif
endif}
{if gblPeriod4=="" then
if DOCUMENT.FORM_4<>"" then
REMOVE_FORM_COMP("Oncology Chemo Orders 4 PP")
REMOVE_FORM_COMP("Oncology Chemo Orders 4 TS")
DOCUMENT.FORM_4 = ""
endif
else
if DOCUMENT.FORM_4=="" then
if DOCUMENT.FORM_2<>"" then
REMOVE_FORM_COMP("Oncology Chemo Orders 2 PP")
REMOVE_FORM_COMP("Oncology Chemo Orders 2 TS")
endif
if DOCUMENT.FORM_3<>"" then
REMOVE_FORM_COMP("Oncology Chemo Orders 3 PP")
REMOVE_FORM_COMP("Oncology Chemo Orders 3 TS")
endif
AddOpenForm("Enterprise\Hematology&Oncology^Oncology Chemo Orders 4 TS", "Oncology Chemo Orders 1 TS", "AFTER_CURRENT", "")
AddOpenForm("Enterprise\Hematology&Oncology^Oncology Chemo Orders 4 PP", "Oncology Chemo Orders 1 TS", "AFTER_CURRENT", "")
DOCUMENT.FORM_4 = "added"
AddOpenForm("Enterprise\Hematology&Oncology^Oncology Chemo Orders 3 TS", "Oncology Chemo Orders 1 TS", "AFTER_CURRENT", "")
AddOpenForm("Enterprise\Hematology&Oncology^Oncology Chemo Orders 3 PP", "Oncology Chemo Orders 1 TS", "AFTER_CURRENT", "")
DOCUMENT.FORM_3 = "added"
AddOpenForm("Enterprise\Hematology&Oncology^Oncology Chemo Orders 2 TS", "Oncology Chemo Orders 1 TS", "AFTER_CURRENT", "")
AddOpenForm("Enterprise\Hematology&Oncology^Oncology Chemo Orders 2 PP", "Oncology Chemo Orders 1 TS", "AFTER_CURRENT", "")
DOCUMENT.FORM_2 = "added"
endif
endif}