How to control the posting on transaction screens in Accpac ERP through your code

By | September 28, 2011

Normally if you click on POST button of any transaction screen it will fire all the standard validations of Accpac and if all the validations PASS it will post the transaction, however if any of the validations fail then Accpac will pop up a error message and won’t post the document.
This is standard behavior, but we often get requirements from end user to add custom validations over and above Accpac’s standard validations, Say for instance; someone may require PO Number as a mandatory field in Order Entry Screen which should be entered by user before posting the document.
Adding validation is not a big deal, where people often get stuck is “How do I control the Posting routine of Accpac so that if My validation fails Accpac Does not Post the document?”
It looks like a challenge until you discover the method to do it, but once you know it, it’s as simple as setting a variables value. Just to save your time here is how to do it
On AccpacOE1100UICtrl1_OnUIAppOpened event first set the data source.

Script

Private Sub AccpacOE1100UICtrl1_OnUIAppOpened()
Set adsOEORDH = AccpacOE1100UICtrl1.UIDSControls.Item(“adsOEORDH”)
End sub

Then on data source change event put your verifications.

Script

Private Sub adsOEORDH_OnRecordChanging(ByVal eReason As AccpacCOMAPI.tagEventReason, pStatus As AccpacCOMAPI.tagEventStatus, ByVal pField As AccpacDataSrc.IAccpacDSField, ByVal pMultipleFields As AccpacDataSrc.IAccpacDSFields)
If eReason = RSN_Addnew or eReason = RSN_Update Then
If (Condtion = true ) Then
Pstatus = Status_OK
Else
Pstatus = Status_Cancel
End if
End if
End sub

condition could be a variable coming from your validation if it’s true that means your validation passed if it’s false that means it failed.
As you can see from the above snippet “Pstatus” is a parameter and posting can be controlled through it. In order to restrict the posting set Pstatus = Status_Cancel and to continue the posting set it to Status_OK.
Hope this helps.