Skip to Content
Former Member
Jul 04, 2014 at 12:41 PM

Recordset throwing error


I am trying to build an addon that does a simple check on a new quote/sales order being added or updated to validate the business partner.

In essence I take the cardcode off the form and check the business partner table to see if Accounts want to stop any orders going out.

I am a little rusty as 6 years since my last addon but I have followed some of the SDK examples.

My code below throws the error: "Object reference not set to an instance of an object"

Private Sub oApp_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles oApp.ItemEvent

Dim oObj As SAPbobsCOM.SBObob

Dim rs As SAPbobsCOM.Recordset


If (pVal.FormType = 139 And pVal.EventType <> SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD) Then

If ((pVal.ItemUID = "1" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED And (pVal.FormMode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE Or pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE)) And (pVal.BeforeAction = True)) Then

'//get the event sending form

oSalesForm = oApp.Forms.GetFormByTypeAndCount(pVal.FormType, pVal.FormTypeCount)

sCardCode = oSalesForm.Items.Item("4").Specific.String

rs = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

rs.DoQuery("SELECT U_OnHold FROM OCRD WHERE CardCode = '" & sCardCode & "'")

sOnHold = rs.Fields.Item(0).Value

If sOnHold = "Y" Then

MsgBox("Business Partner is ON HOLD, Please contact accounts to approve this document", MsgBoxStyle.Exclamation, "BP On Hold")

End If

End If

End If

Catch ex As Exception


End Try

End Sub