Using window properties and methods

The following table explains the available window methods and properties. The remainder of this section explains some of the more common methods and properties you’ll use when working with windows, as well as additional ways you can use windows.




Activate method

Activates the window.

Caption property

Specifies the window’s title.

Close method

Closes the window.

EventMode property

Specifies whether window events occur for the original or modified version of the window.

Height property

Specifies the height of the window’s client area (in pixels). The client area is the window less the window’s title bar.

Hide method

Hides an open window.

IsLoaded property

Specifies whether the window is open (not necessarily displayed).

Left property

Specifies the horizontal position (in pixels) of the window.

Move method

Moves a window to a specified set of coordinates (in pixels).

Name property

Specifies the internal name VBA uses for the window.

Open method

Opens a window.

PullFocus method

Removes the focus from the window.

Show method

Shows a window that’s hidden using the Hide method.

Top property

Specifies the vertical position of the window (in pixels).

Visible property

Specifies whether the window is visible.Width propertySpecifies the width of the window (in pixels).

Required property

Specifies whether the user entered data in all fields whose Required property is True.

Opening and closing windows

You can open a Microsoft Dynamics GP window directly or indirectly through VBA. To open and close it directly, use the window object’s Open method and Close method. The following event procedure opens the Customer Maintenance window after the user logs in:

Private Sub Window_AfterClose()
	'The user logged in. Open the Customer Maintenance window.
End Sub

The recommended method is to open a window indirectly, using VBA to provide the navigation that displays the window, such as programmatically “clicking” a lookup button that displays a lookup window:

Private Sub ShippingMethod_AfterGotFocus()
	If ShippingMethod.Empty = True Then
	'No shipping method specified. Click the lookup button
		LookupButtons = 1
	End If
End Sub

Microsoft Dynamics GP application code attached to navigational controls (such as the lookup button) prepares the window to display data correctly. “Clicking” these controls using VBA ensures that this processing occurs.

Working with forms

In Microsoft Dynamics GP, forms are a logical grouping of windows that function together to perform a specific task. For instance, the Customer Maintenance, Customer Account Maintenance and Customer Maintenance Options windows are all part of the same form.

When you open a window, Microsoft Dynamics GP opens all windows in the window’s form invisibly, then displays the first window in the form (the parent window). The child windows in the form remain invisible, but loaded (their IsLoaded property is True).

If you open a form’s child window through VBA, Microsoft Dynamics GP displays the form’s parent window as well as the child window. Any other child windows remain loaded and invisible.

When you display a record in the parent window, Microsoft Dynamics GP updates data in the invisible child windows so each contains data specific to the current record. Since these child windows are loaded, you can reference data in these fields using VBA.

For instance, when you open the Customer Maintenance window and display a customer record, you can reference fields in the Customer Maintenance Options window for that customer. In the following example, the event procedure stops the user from saving a customer record in the Customer Maintenance window if the user hasn’t entered a currency ID in the Customer Maintenance Options window:

Private Sub Save_BeforeUserChanged(KeepFocus As Boolean, _
CancelLogic As Boolean)
	If CustomerMaintenanceOptions.CurrencyID.Empty = True Then
		'Cancel the save
		CancelLogic = True
		'Prompt the user to enter a currency ID
		MsgBox "You must enter a currency ID for this customer."
		CustomerMaintenanceOptions.Visible = True
	End If
End Sub

Use the Modifier’s Form Definition window to find out which windows are part of a form.

Activating a window

The VBA Activate method activates a visible, open window, making it the frontmost window, or expands it if it’s minimized. The Activate method also causes the window’s activate event to occur. In the following example, the event procedure activates the Invoice Entry window after closing the Invoice Batch Entry window:

Private Sub Window_AfterClose()
	If InvoiceEntry.Visible = True Then
	End If
End Sub

Hiding windows

The VBA Hide method (window) hides a window you’ve opened, making it invisible. The Visible property (window), when set to False, also makes a window invisible. While invisible, the window is open (its IsLoaded property is True) and data in the window is accessible.

Making a window invisible is useful if you need to reference data contained in the window without necessarily displaying the window to the user. For example, when the user enters a transaction amount in the Receivables Transaction Entry window, the following event procedure compares the amount with the maximum batch total in an invisible Receivables Batch Entry window:

Private Sub SalesAmount_BeforeUserChanged(KeepFocus As Boolean, _
CancelLogic As Boolean)
	If BatchID.Empty = False Then
		'The user selected a batch
		'Click the expansion button to open the Batch Entry window 
		ExpansionButtons = 1
		'Make the window invisible
		ReceivablesBatchEntry.Visible = False
		'Compare the batch total to the trx amount entered
		If CCur(SalesAmount) >CCur(ReceivablesBatchEntry _ 
		.BatchTotal) Then
			MsgBox "Amount exceeds batch limit. Select another batch."
			'Clear the batch ID field and move the focus there
			BatchID.Empty = True
		End If
		'Close the window
	End If
End Sub

The Show method (window) displays an invisible window. Setting the window’s Visible property (window) to True also displays an open window. You can open a window invisibly by setting the OpenVisible parameter of the window’s BeforeOpen event to False.

Moving and resizing a window

You can resize or reposition a window using the Height property (window), Left property (window), Top property (window) and Width property (window). Resizing and repositioning a window is useful for organizing windows more efficiently within the visible workspace. In the following example, the event procedure runs before the Customer AddressMaintenance window opens. The event procedure verifies the Customer Maintenance window is open, then positions the Customer Address Maintenance window below and to the right:

Private Sub Window_BeforeOpen(OpenVisible As Boolean)
If CustomerMaintenance.Visible = True Then
	'The Customer Maintenance window is open
	CustomerAddressMaintenance.Left = CustomerMaintenance.Left + 25
	CustomerAddressMaintenance.Top = CustomerMaintenance.Top + 100
End If
End Sub

Changing a window title

The Caption property allows you to set the window’s caption (title). The following example changes the title of the CustomerMaintenance window when the window opens. It also changes the prompt for one of the fields in the window.

Private Sub Window_BeforeOpen(OpenVisible As Boolean)
	'Change the title of the window
	CustomerMaintenance.Caption = "Client Maintenance"
	CustomerMaintenance.CustomerID.Caption = "Client ID"
End Sub

Using modified or original windows

You can choose whether window events occur for the modified or original version of a window using the EventMode property (window). If you modify a window using the Modifier, you can change the window’s EventMode property to emModifiedOnly. This allows VBA events to occur for the modified window only.

If you make no modifications to the window using the Modifier, you can set the EventMode property to emOriginalOnly. This allows VBA events to occur for the original window only.

Renaming a window

The Name property (window) allows you to change VBA’s internal reference to a window object. Note that this is not the same as the Caption property, which allows you to change the window’s title. If you change the window’s Name property using the Visual Basic Properties window, the name will change in your project. You should then recompile your project to replace any references to that window with the new name. You’ll find it necessary to rename a window if its name conflicts with other object names in your project, such as reserved words in VBA.

Documentation Feedback