Changed event

The VBA Changed field event always occurs for a field when its contents change. This includes:


The most common situation to use the Changed event is when you want to execute VBA code for window fields that Microsoft Dynamics GP updates. This occurs most often when the accounting system retrieves a record from a table, then displays the record’s contents in window fields. The AfterUserChanged and BeforeUserChanged events won’t occur for these fields, since the application, not the user, changes the contents of the field.

Exercise caution when using the Changed event. In many cases, Microsoft Dynamics GP may cause the Changed event to occur numerous times for the same field even though the value of the field may not visibly change. This will execute the associated VBA event procedure each time the event occurs.

For example, as the user browses through records in the Receivables Transaction Entry window, Microsoft Dynamics GP sets window field values for each record. The following Changed event procedure runs for the Document Date field. Each time the user moves to a new record, it checks the value of the document date, and displays a message if the document is older than 30 days:

Private Sub DocumentDate_Changed()
	Dim DaysOld As Integer
	'Check the document date using the VBA Date function
	If CDate(DocumentDate) < Date - 30 Then
		'The document is at least 30 days old
		DaysOld = Date - CDate(DocumentDate)
		MsgBox "This document is " + Str(DaysOld) + " days old." + _
		"Please post."
	End If
End Sub

Documentation Feedback