Skip to Content
Former Member
Apr 11, 2012 at 02:08 PM

Sales Order Form: Validate Event for Customer Reference No Field


Hi to all.

My objective is to create code/logic to check if a duplicate PO for a given customer has been entered on the sales order form and prevent it.

The desired action, if a duplicate was found, is to give a message box to the user indicating the problem. When the box is closed, I want to clear the Customer Reference No field on the form and then set focus back to the field for a new entry.

I did this. It all works, except.....

Nothing I do can cause the focus to be set to the Customer Reference No field. It always advances to the next field, which is currency.

Here is my event code.....

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

Dim oEditCardCode As SAPbouiCOM.EditText

Dim oEditNumAtCard As SAPbouiCOM.EditText

'check if sales order form generated this event

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

'// get access to the event sending form

oOrderForm = SBO_Application.Forms.GetFormByTypeAndCount(pVal.FormType,pVal.FormTypeCount)

'validation test for duplicate PO number

If ((pVal.ItemUID = "14") And (pVal.EventType = SAPbouiCOM.BoEventTypes.et_VALIDATE) And (pVal.InnerEvent = False) And (pVal.BeforeAction = False)) Then

'Get access to the text boxes in order to get the existing values

oEditCardCode = oOrderForm.Items.Item("4").Specific

oEditNumAtCard = oOrderForm.Items.Item("14").Specific

Dim ActiveItem As String = oOrderForm.ActiveItem

If oEditNumAtCard.Value <> "" Then

'Validate entered PO here.

'see if any orders exist with the same BP and PO numbers in the order table

If ManageSQLServer.ReturnPOCount(Trim(oEditCardCode.Value), Trim(oEditNumAtCard.Value)) Then

'one or more was found, so message user

SBO_Application.MessageBox("Please check the PO number; the entered PO number already exists for this customer.")

'set focus to edit box

'oOrderForm.ActiveItem = ActiveItem

'Make PO edit box empty

oEditNumAtCard.Value = ""

End If

End If

End If

End If

End Sub

Can anyone see an obvious error? I personally think the form is overriding my set focus code somehow.