Error 1007   Unsafe operation. An attempt was made to set a value that violates the applications business logic. This operation could compromise the integrity of the application.


You attempted to set a field’s value from “outside” the field (before the field gains focus), such as by using the window’s BeforeOpen or AfterOpen event, or another field’s BeforeUserChanged or AfterUserChanged event.

When you set the value of a field before the field gains focus, VBA automatically runs the Microsoft Dynamics GP user changed event for the field you’re setting. This is necessary so any accounting system application code associated with these events can verify the field’s value. Although Microsoft Dynamics GP doesn’t perform this verification for all fields, they will perform verification for fields that affect business logic (such as an invoice discount percent, or a tax amount) or for add-on-the-fly fields. If the accounting system determines that the field’s value is invalid, it will first display its error dialog, followed by the VBA error dialog.


There are three ways to avoid this type of error:

Private Sub ShippingMethod_AfterGotFocus()
	'Set the Shipping Method field to a value that doesn't exist.
	ShippingMethod = "NEW"
End Sub

Private Sub CustomerID_AfterUserChanged()
	'Move the focus to the field, then set the value 
End Sub

Documentation Feedback