on 09-08-2008 12:06 PM
I am updating the form of item master.For this I have added a new button.On the click event of this event my new form opens.I want to load this new button every time I open item master.I tried on the form load event of item master but it did not worked.The code is as,
Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
If pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_LOAD And pVal.FormType = "150" Then
EditForm(pVal.FormTypeEx, pVal.FormTypeCount)
End If
End Sub
Private Sub EditForm(ByVal intType As Integer, ByVal intCount As Integer)
Dim objNewItem As SAPbouiCOM.Item
Dim objButton As SAPbouiCOM.Button
objForm = SBO_Application.Forms.GetFormByTypeAndCount(intType, intCount)
'objForm = SBO_Application.Forms.ActiveForm
objNewItem = objForm.Items.Add("btnIISP", SAPbouiCOM.BoFormItemTypes.it_BUTTON)
objNewItem.Left = 900
objNewItem.Width = 100
objNewItem.Top = 568
objNewItem.Width = 100
objNewItem.Height = 20
objNewItem.Description = "IISP"
objButton = objForm.Items.Item("btnIISP").Specific
objButton.Caption = "Inspection Details"
objForm.Refresh()
End Sub
Dear friends,
The problem was with the position of the button.I made change in the function EditForm as
Private Sub EditForm(ByVal intType As Integer, ByVal intCount As Integer)
Dim objNewItem As SAPbouiCOM.Item
Dim objButton As SAPbouiCOM.Button
Try
objForm = SBO_Application.Forms.GetFormByTypeAndCount(intType, intCount)
If objForm.Items.Count = 242 Then
objNewItem = objForm.Items.Add("btnIISP", SAPbouiCOM.BoFormItemTypes.it_BUTTON)
objNewItem.Left = objForm.Width - 80
objNewItem.Top = objForm.Items.Item("2").Top
objNewItem.Width = 100
objNewItem.Height = 20
objNewItem.Description = "IISP"
objNewItem.Visible = True
objButton = objForm.Items.Item("btnIISP").Specific
objButton.Caption = "Inspection Details"
objForm.Refresh()
End If
Catch ex As Exception
SBO_Application.MessageBox(ex.Message)
End Try
End Sub
When the form was created the button was getting placed outside the form.Also,I call the function on the form resize rather than form load as,
If pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_RESIZE And pVal.FormType = "150" And pVal.Action_Success = True Then
objForm = SBO_Application.Forms.GetFormByTypeAndCount(150, 1)
If objForm.Items.Count = 243 Then
objForm.Items.Item("btnIISP").Top = objForm.Items.Item("2").Top
objForm.Items.Item("btnIISP").Left = objForm.Width - (objForm.Items.Item("btnIISP").Width) - 20
Else
EditForm(pVal.FormType, pVal.FormTypeCount)
End If
End If
Thanks for u r valuable help.
Regards,
Dilip Kumbhar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
pVal.EventType < > SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD
pVal.EventType not equal to Form_UnLoad
Typing mistake
Regards,
Murtaza
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dilip,
Try this out in Item Event
If pVal.FormType = 150 and pVal.EventType <> SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD And pVal.BeforeAction = True Then
EditForm(pVal.FormTypeEx, pVal.FormTypeCount)
End If
Hope it helps
Regards,
Murtaza
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dilip,
It seems you might have declared objForm as SAPbouiCOM.Forms, which is the collection of Forms.
When I changed the declaration of this object to SAPbouiCOM.Form (a single form), your code worked correctly for me. (although I did have to move the position of the newly created button as it did not appear for me at first):
Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent,
ByRef BubbleEvent As Boolean) Handles oApp.ItemEvent
If pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_LOAD And pVal.FormType = "150" And
pVal.BeforeAction = False Then
EditForm(pVal.FormTypeEx, pVal.FormTypeCount)
End If
End Sub
Private Sub EditForm(ByVal intType As Integer, ByVal intCount As Integer)
Dim objNewItem As SAPbouiCOM.Item
Dim objButton As SAPbouiCOM.Button
Dim objForm As SAPbouiCOM.Form
Try
objForm = oApp.Forms.GetFormByTypeAndCount(intType, intCount)
'objForm = oApp.Forms.ActiveForm
objNewItem = objForm.Items.Add("btnIISP", SAPbouiCOM.BoFormItemTypes.it_BUTTON)
objNewItem.Left = 100
objNewItem.Width = 100
objNewItem.Top = 100
objNewItem.Width = 100
objNewItem.Height = 20
objNewItem.Description = "IISP"
objButton = objForm.Items.Item("btnIISP").Specific
objButton.Caption = "Inspection Details"
objForm.Refresh()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Each of the methods you were using to get the form returned a single form but it seems your variable might have been a collection of forms so VB was unable to cast directly. Try running this modified code and see does the issue continue to occur.
If it does, please enter the exception raised that appears in the message box and we will use this to troubleshoot the error.
Regards,
Niall
SAP Business One Forums Team
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
as far as I can see you do the same as me (here it works) but you don't do it only BeforeAction:
If pval.BeforeAction And pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_LOAD And pVal.FormType = "150" Then
EditForm(pVal.FormTypeEx, pVal.FormTypeCount)
End If
Another tip:
When I add items to system forms I always use the position-data of existing items as reference for the position of my own item:
Dim oItmRef As SAPbouiCOM.Item
Dim oItm As SAPbouiCOM.Item
' Inv.-Type (CC, OP...)
oItmRef = oForm.Items.Item("46")
oItm = oForm.Items.Add("CBX_INVTYP", SAPbouiCOM.BoFormItemTypes.it_COMBO_BOX)
oItm.Left = oItmRef.Left
oItm.Top = oItmRef.Top + 15 ' beneath item 46
oItm.Width = oItmRef.Width
oItm.Height = oItmRef.Height
oItm.FromPane = oItmRef.FromPane
oItm.ToPane = oItmRef.ToPane
Much less to measure and think about...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try this,
If pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_LOAD And pVal.FormType = "150" And pVal.BeforeAction = False Then
EditForm(pVal.FormTypeEx, pVal.FormTypeCount)
End If
End Sub
and do use a Try Catch block to catch any errors,
Hope it helps,
Vasu Natari.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Vasu,
I tried u r code but it did not worked.My new button did not appeared in the load event.I have been testing this form using the following code
If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CLICK And pVal.Action_Success = True And pVal.FormType = "169" And pVal.ColUID = "7" And pVal.ItemUID = "6" And pVal.Row = 9 Then
EditForm(150, pVal.FormTypeCount)
end if
This code worked perfectly.The path of above event is
Main Menu -> Inventory ->Item Master Data
When I clicked on Item Master Data the above event fired.But now I want to display the button on the load event of item master.
That code did not worked.It did not displayed any error.
When I called the form on the click event ,form was displayed first and then the event fired. i.e Form -> Event
When I called the form on the load event,event was fired first and then form was displayed i.e Event -> Form.
Edited by: Dilip Kumbhar on Sep 8, 2008 5:22 PM
Hi Dilip,
the code you are using is in click event
If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CLICK And pVal.Action_Success = True And pVal.FormType = "169" And pVal.ColUID = "7" And pVal.ItemUID = "6" And pVal.Row = 9 Then
EditForm(150, pVal.FormTypeCount)
end if
Change the event to load event and take the reference of cancel button to set the properties of the new button.
So that it places relative to that button
Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
If pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_LOAD And pVal.FormType = "150" and pVal.Action_Success = True and pVal.BeforeAction=false Then
EditForm(pVal.FormTypeEx, pVal.FormTypeCount)
End If
End Sub
Private Sub EditForm(ByVal intType As Integer, ByVal intCount As Integer)
Dim objNewItem As SAPbouiCOM.Item
Dim objButton As SAPbouiCOM.Button
Dim oItmRef As SAPbouiCOM.Item
objForm = SBO_Application.Forms.GetFormByTypeAndCount(intType, intCount)
'objForm = SBO_Application.Forms.ActiveForm
objNewItem = objForm.Items.Add("btnIISP", SAPbouiCOM.BoFormItemTypes.it_BUTTON)
oItmRef = objForm.Items.Item("2")
objNewItem.Left = oItmRef.Left + 100
objNewItem.Width =oItmRef.Width
objNewItem.Top = oItmRef.Top
objNewItem.Height = oItmRef.Height
objButton = objForm.Items.Item("btnIISP").Specific
objButton.Caption = "IISP"
objForm.update()
objForm.Refresh()
End Sub
try this code
thanks & regards
Vishnu
Edited by: Vishnu Kumar Reddy on Sep 8, 2008 2:19 PM
Vishnu,
u r code did not worked.In the click event the form loaded first and then the event fired (function was called).This could display the new button.
I want a event which will load the form first and then call the function to display button.Which is the event which executes in this way only once other than form load ?
User | Count |
---|---|
91 | |
10 | |
10 | |
6 | |
5 | |
5 | |
5 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.