cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to catch the form load event.

Former Member
0 Kudos

Hi,

I am trying to catch the form load event for the Sales Quotation form.

My task is to add a new button when the form opens.

This is how my code looks -

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

If pVal.FormType = 149 Then

If pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_LOAD Then

' Add button on form load

oForm = SBO_Application.Forms.Item(FormUID)

oItem = oForm.Items.Add("Button", SAPbouiCOM.BoFormItemTypes.it_BUTTON)

oItem.Left = 140

oItem.Width = 65

oItem.Top = oForm.ClientHeight - 30

oItem.Height = 19

oButton = oItem.Specific

oButton.Caption = "Button"

End If

End If

End Sub

But the form load event never occurs and thus my code is not executed. SBO_Application_ItemEvent is not called when the form is opening.

I am able to catch the click events on the form.

What am I missing?

Please help me solve this issue.

Thank you for your help.

Regards,

Sheetal

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

try this, it's working for me on the Deliveries form

Private Sub sboApplication_ItemEvent(ByVal FormUID As String, pVal As SAPbouiCOM.IItemEvent, BubbleEvent As Boolean)

If pVal.FormType = 140 Then

If pVal.EventType = et_FORM_LOAD Then

Set frmDelivery = sboApplication.Forms.GetFormByTypeAndCount(pVal.FormType, pVal.FormTypeCount)

'here I do something like adding items on the form

...

Of course remove any event filter if you set 'em.

I know, I'm using the deprecated method instead of GetForm, but it works fine

Finally, let me say that event handling in SBO is so poorly documented that you have to experiment a bit to achieve some good results.

Hope this helps

Bye

Former Member
0 Kudos

Thank you all for your help. My problem is more fundamental. Here is the simplest possible code that catches any event that is received and displays it.

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

System.Diagnostics.Debug.WriteLine(pVal.EventType)

BubbleEvent = True

Return

end sub

When the addon is running and I bring up the standard form "Sales Quotation," I never recive any et_FORM_LOAD event. However, when I click my mouse on the form, I do see et_CLICK event being displayed in the debugger. This is very confusing. Can someone please tell me what possibly could be happening?

Thank you in advance for your help.

Sheetal

Former Member
0 Kudos

I am using SAP2004A.

I copied and pasted your code in one of my projects and it works, and gives me the button. I use VB6 , so I had to modify the code slightly, but that was only syntax changes, nothing elese. I do not understand why you don't get the button, try removing all the filters if you have and then work from there. here is my code anyway.

**********************************

If pVal.FormType = 149 Then

If pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_LOAD Then

' Add button on form load

Dim oform As SAPbouiCOM.Form

Dim oItem As SAPbouiCOM.Item

Dim oButton As SAPbouiCOM.Button

Set oform = mObjSBOApplication.Forms.Item(FormUID)

Set oItem = oform.Items.Add("Button", SAPbouiCOM.BoFormItemTypes.it_BUTTON)

oItem.Left = 140

oItem.Width = 65

oItem.Top = oform.ClientHeight - 30

oItem.Height = 19

Set oButton = oItem.Specific

oButton.Caption = "Button"

End If

End If

Former Member
0 Kudos

Indeed it was that the event was filtered.

Thanks for getting that to my notice.

My problem is solved.

Regards,

Sheetal

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

for my knowledge the FORM_LOAD event doesn't raise a BeforeAction, so it couldn't be an error.

The EventFilter could be a good reason...

I don't really see an error in your code, you could try to set some breakpoints to see what instructions are exectuted correctly.

In my codes i'm writing something similar to add buttons... the difference is that i use the new SDK 2004 objects and methods:

--- pVal.FormTypeEx = "149" ---

--- oForm = SBO_Application.GetForm(pVal.FormTypeEx, pVal.FormTypeCount) ---

but i don't think this can solve your problem...

Kind regards,

Fabio Salucci

Former Member
0 Kudos

Hi

Try to change in your code:

oForm = SBO_Application.Forms.Item(FormUID)

for this

oForm = SBO_Application.Forms.getactiveform()

or this

oForm = SBO_Application.Forms.getform("149",1)

This is the code that i have used for adding a button to a system form, you only need to change 139 to 149.

Perhaps you may try SBO_App.forms.getactiveform instead getform("139",1).

if pVal.typeEx="139" then
 If pVal.EventType = et_FORM_LOAD Then
    Dim oForm As SAPbouiCOM.Form
    Dim obj As SAPbouiCOM.Item
    Dim btn As SAPbouiCOM.Button
    Set oForm = SBO_App.Forms.GetForm("139", 1)
    Set obj = oForm.Items.Add("BtnDsdFac", it_BUTTON)
    obj.Left = oForm.Items.Item("37").Left + 120
    obj.Width = 120
    obj.Top = oForm.Items.Item("37").Top
    obj.Height = oForm.Items.Item("37").Height
    Set btn = objeto.Specific
    btn.Caption = "caption of button"
 end if
end if

Regards

Salvador Biot

Former Member
0 Kudos

Hi Sheetal,

Have you defined an EventFilter before this? This could be a reason why it doesn´t get fired.

Did you try a messagebox just where you get the form?

Becouse I can see that you are not managing the BeforeEvent property, and then it would execute your code twice. And as your button ID would be repeated, it should give an error.

Are you sure it doesnt get fired?

Regards,

Ibai Peñ