With CBF, you also have the added ability to cancel specific events through the use of a parameter in the event's procedure. An example of this is again the "OnOpen" event and its event procedure, prototyped as follows:
Sub Form_Open (Cancel as Integer)
By setting the Cancel parameter to True before exiting the event procedure, we can tell the form to stop loading. This allows us to move more code behind the Wizard form. For example, before the Subform Wizard can begin, it must first check that the subform the user is linking contains at least one field. If the subform does not contain a field, the Wizard should stop and alert the user before opening the form. Without the capability to cancel a form open event, this validation code must be placed in the entry point, adding more global code. With the cancel event, we can move this CBF and place it in the form's OnOpen event where, if the condition is not met, we can stop the form from being displayed. Here's the code:
' If the subform does not contain any controls halt the Wizard iSub = frmSubform.Count If (iSub = 0) Then ss_DisplayErr errSUBFORMEMPTY Cancel = True Exit Sub End If