Window close events

VBA window close events occur when the user closes the window, either before or after the Microsoft Dynamics GP code for the window close event runs. Microsoft Dynamics GP uses the window close event to display a modal dialog asking the user whether to save changes to the record.

BeforeClose event

The BeforeClose event occurs before Microsoft Dynamics GP application code runs for the window close event. The primary use for this event is to cancel the window close if the contents in the window don’t meet certain criteria. The following event procedure for the Invoice Entry window checks whether the user entered a comment ID for the transaction, and displays a message dialog. If the user clicks Yes, the procedure cancels the close using the AbortClose parameter, and the user can enter a comment ID:

Private Sub Window_BeforeClose(AbortClose As Boolean)
	Dim Response As Integer
	If CommentID.Empty = True Then
		'Display a message box
		Response = MsgBox("Do you want to enter a Comment?", vbYesNo)
		If Response = vbYes Then
			'They want to enter a comment
			AbortClose = True
		End If
	End If
End Sub

AfterClose event

The AfterClose event occurs after the Microsoft Dynamics GP application code runs for the window close event. The AfterClose event is a general-purpose event you can use to perform any “clean-up” tasks, such as closing other windows. For example, the following event procedure runs when the Customer Maintenance window closes. It closes the Customers And Prospects lookup window if it’s open (its IsLoaded property is True):

Private Sub Window_AfterClose()
	If CustomersAndProspects.IsLoaded = True Then
	End If
End Sub

Documentation Feedback