Hi Rick
Situation:
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.
Solution:
There are three ways to avoid this type of error:
• Whenever possible, set a field’s value from “inside” the field, after it has gained focus, using the field’s AfterGotFocus or BeforeGotFocus field events. If your event procedure sets an invalid value, the accounting system will still display a dialog, but VBA won’t generate the error:
Private Sub ShippingMethod_AfterGotFocus()
'Set the Shipping Method field to a value that doesn't exist.
ShippingMethod = "NEW"
End Sub
• If you set the value from “outside” the field, before the field has gained focus, use the Focus method with the setvalue parameter in your event procedure. The Focus method moves the focus to the field, then sets it to the value of the setvalue parameter:
Private Sub CustomerID_AfterUserChanged()
'Move the focus to the field, then set the value
ShippingMethod.Focus("NEW")
End Sub
• Only set fields from “outside” the field if you know the accounting system isn’t performing field verification. Microsoft Dynamics GP performs verification for fields that affect business logic (such as an invoice discount percent, or a tax amount) or for add-on-the-fly fields. You can set the value of add-on-the-fly fields only if the add-on-the-fly value already exists as a record (such as an existing shipping method).