Programming a window object

There are two primary ways you can write VBA code for a window object: using a window event procedure, or referencing the window in procedures throughout your project.

Using a window event procedure

A window event procedure executes VBA code when a user opens, closes or activates a window in Microsoft Dynamics GP. This is useful for setting default window field values when the window opens, or closing other windows when the window closes. In the following example, an event procedure sets default field values when the Invoice Entry window opens:

Private Sub Window_AfterOpen()
	'Set the sort list to "by Date"
	SortBy = 3
	'Set the document type list to "Returns"
	DocumentType = 2
End Sub

The following section, Using window events, explains each type of window event you can use to execute VBA code. Windows also contain window fields that you can reference and manipulate through VBA. Refer to Programming Window Fields for more information about using window fields.

Referencing the window object

After you create a window object in your project, any VBA code you write in your VBA project has full access to the window object, its properties and its methods. In the following example, a push button on a VBA form opens a window using the window’s Open method:

Private Sub OpenCustomerMaintenance_Click()
	CustomerMaintenance.Open
End Sub

The section titled Using window properties and methods explains the methods and properties available to procedures in your VBA project.


Documentation Feedback