VBA window open events occur when the user opens the window, either before or after the Microsoft Dynamics GP code for the window open event runs. Microsoft Dynamics GP uses the window open event to set default field values, such as a default document date or a sorting order.
The BeforeOpen event occurs before the Microsoft Dynamics GP code runs for the window open event. It’s useful when you want to set default field values in the window, while still allowing any Microsoft Dynamics GP application code to override your defaults. In the following example, the event procedure sets the Checkbook ID field when the Invoice Batch Entry window opens. If this window displays an existing record when opened (such as when opened from a zoom field), Microsoft Dynamics GP application code overrides this value with the value stored with the record:
Private Sub Window_BeforeOpen(OpenVisible As Boolean) 'Set the checkbook ID CheckbookID = "PETTY CASH" End Sub
This event also includes the OpenVisible parameter. When set to False, this specifies that the window should open invisibly.
The AfterOpen event occurs after the Microsoft Dynamics GP code runs for the window open event. It’s useful for overriding any default values that were set for window fields. In the following example, the event procedure marks both check box controls when the Sales Territory Maintenance window opens. Since Microsoft Dynamics GP application code sets defaults for these fields when the window opens, using the AfterOpen event overrides the defaults:
Private Sub Window_AfterOpen() 'Set both check boxes when the window opens MaintainHistory = 1 MaintainHistory1 = 1 End Sub