cancel
Showing results for 
Search instead for 
Did you mean: 

Error : Open New Form

Former Member
0 Kudos

Hai To All,

In my form i have one button named "Stock Posting" in run mode if i click tht iam creating another form and open it. If i click that button again i got the error as "Form Already Exists" how to rectify tht error.

Regards,

Anitha

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Aninazir,

No two forms can have the same UniqueID, so you need to generate a new and unique ID each time you open you form.

Please check this post for some code samples

[]

Regards,

Vítor Vieira

Former Member
0 Kudos

Hi,

Before opening the form check if the form is already open or not...

Public Shared Function IsFormExits(ByRef strFormName As String, ByRef SBO_Application As SAPbouiCOM.Application) As Boolean
        Dim oForm As SAPbouiCOM.Form

        'loop in all the open forms
        For Each oForm In SBO_Application.Forms
            If InStr(1, oForm.GetAsXML, strFormName, CompareMethod.Text) > 0 Then
                SBO_Application.MessageBox("The form is already opened")
                Return True 'form exist

            End If

Thats what i use..

Hope it helps u..

Vasu Natri..

Former Member
0 Kudos

See this is my Code,

Private Sub CreateMySimpleForm()

Dim CP As SAPbouiCOM.FormCreationParams

Dim oForm As SAPbouiCOM.Form

Dim oItem As SAPbouiCOM.Item

Dim oGrid As SAPbouiCOM.Grid

If IsFormExits("stockposting", oApplication) = False Then

CP = oApplication.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_FormCreationParams)

CP.BorderStyle = SAPbouiCOM.BoFormBorderStyle.fbs_Sizable

' CP.FormType = "SAMPLE"

CP.UniqueID = "stockposting"

oForm = oApplication.Forms.AddEx(CP)

' Set form width and height

oForm.Height = 305

oForm.Width = 600

oForm.Title = "Inventory Transfer"

'' Add a Grid item to the form

oItem = oForm.Items.Add("MyGrid", SAPbouiCOM.BoFormItemTypes.it_GRID)

' Set the grid dimentions and position

oItem.Left = 20

oItem.Top = 20

oItem.Width = 550

oItem.Height = 200

Dim ocol As SAPbouiCOM.GridColumn

' Set the grid data

oGrid = oItem.Specific

oForm.DataSources.DataTables.Add("MyDataTable")

Dim str = "select DocNum,filler 'From Location' ,ItemCode,dscription 'Description',Quantity,whscode 'To Location' from owtr a, wtr1 b where a.docentry=b.docentry and comments like 'Posted From Inward Inspection%' and ref2='" & oDBDSHeader.GetValue("DocNum", 0) & "' "

oForm.DataSources.DataTables.Item(0).ExecuteQuery(str)

oGrid.DataTable = oForm.DataSources.DataTables.Item("MyDataTable")

' Set columns size

oGrid.Columns.Item(0).Width = 50

oGrid.Columns.Item(1).Width = 60

oGrid.Columns.Item(2).Width = 130

oGrid.Columns.Item(0).Editable = False

oGrid.Columns.Item(1).Editable = False

oGrid.Columns.Item(2).Editable = False

oGrid.Columns.Item(3).Editable = False

oGrid.Columns.Item(4).Editable = False

oGrid.Columns.Item(5).Editable = False

oForm.Visible = True

oGrid.Columns.Item(0).Type = SAPbouiCOM.BoGridColumnType.gct_EditText

ocol = oGrid.Columns.Item(0)

ocol.LinkedObjectType = 67

End If

End Sub

Iam calling this function in Button click.........

In this how to check the form exits.......

Regards,

Anitha.....

Edited by: Aninazir on Sep 10, 2009 1:16 PM

Former Member
0 Kudos

Aninazir,


CP.UniqueID = "stockposting"

When you try to open the form for the second time, B1 will detect another form with the unique Id = stockposting. This is why your are getting that error.

Each time you open your form, you need to get a suffix for the form's UniqueID. Most programmers add a counter.


CP.UniqueID = "stockposting_" & GetFormNextSuffix("SAMPLE")

The GetFormNextSuffix(FormType), search's the oApplication.Forms collection for the Highest ID for forms of that type and returns the next ID

Example:

oApplication.Forms collection hold these forms

1. Form(Type: 169, UniqueId: F_1)

2. Form(Type: 133, UniqueId: F_2)

3. Form(Type: SAMPLE, UniqueId: stockposting_1)

4. Form(Type: SAMPLE, UniqueId: stockposting_2)

Calling GetNextFormSuffix("SAMPLE") whould return "3".

Regards,

Vítor Vieira

Former Member
0 Kudos

Ok Thanks,

but how to apply in code and check

Regards,

Anitha

Former Member
0 Kudos

Aninazir,


    Private Function MaxFormType(ByRef oCompany As SAPbobsCOM.Company, ByRef oApplication As SAPbouiCOM.Application, ByRef Tipo As String) As Long
        MaxFormType= 0

        Try
            For Each iform As SAPbouiCOM.Form In oApplication.Forms
                If iform.TypeEx = Tipo Then
                    If iform.TypeCount > MaximoTipoForm Then
                        MaxFormType = iform.TypeCount
                    End If
                End If
            Next
            MaxFormType = MaxFormType + 1
        Catch ex As Exception
            oApplication.MessageBox("MaxFormType(" & Tipo & "): " & oCompany.GetLastErrorCode.ToString & ", " & ex.ToString)
        End Try
    End Function

Regards,

Vítor Vieira

Former Member
0 Kudos

What is that MaximoTipoForm Mean???

Regards,

Anitha

Former Member
0 Kudos

Aninazin,

It's the original name of my function (and return value) that I translated for you benefit.

Here is the code corrected


    Private Function MaxFormType(ByRef oCompany As SAPbobsCOM.Company, ByRef oApplication As SAPbouiCOM.Application, ByRef FormType As String) As Long
        MaxFormType = 0
 
        Try
            For Each iform As SAPbouiCOM.Form In oApplication.Forms
                If iform.TypeEx = FormType Then
                    If iform.TypeCount > MaxFormType Then
                        MaxFormType = iform.TypeCount
                    End If
                End If
            Next
            MaxFormType = MaxFormType + 1
        Catch ex As Exception
            oApplication.MessageBox("MaxFormType(" & Tipo & "): " & oCompany.GetLastErrorCode.ToString & ", " & ex.ToString)
        End Try
    End Function

Regards,

Vítor Vieira

Former Member
0 Kudos

Thanks Victor,,,

Iam calling this function before my code,

Private Sub CreateMySimpleForm()

Dim CP As SAPbouiCOM.FormCreationParams

Dim oForm As SAPbouiCOM.Form

Dim oItem As SAPbouiCOM.Item

Dim oGrid As SAPbouiCOM.Grid

CP = oApplication.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_FormCreationParams)

CP.BorderStyle = SAPbouiCOM.BoFormBorderStyle.fbs_Sizable

' CP.FormType = "SAMPLE"

CP.UniqueID = "stockposting"

oForm = oApplication.Forms.AddEx(CP)

If MaxFormType(oCompany, oApplication, "stockposting") Then

CP = oApplication.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_FormCreationParams)

CP.BorderStyle = SAPbouiCOM.BoFormBorderStyle.fbs_Sizable

' CP.FormType = "SAMPLE"

CP.UniqueID = "stockposting"

oForm = oApplication.Forms.AddEx(CP)

' Set form width and height

oForm.Height = 305

oForm.Width = 600

oForm.Title = "Inventory Transfer"

'' Add a Grid item to the form

oItem = oForm.Items.Add("MyGrid", SAPbouiCOM.BoFormItemTypes.it_GRID)

' Set the grid dimentions and position

oItem.Left = 20

oItem.Top = 20

oItem.Width = 550

oItem.Height = 200

Dim ocol As SAPbouiCOM.GridColumn

' Set the grid data

oGrid = oItem.Specific

oForm.DataSources.DataTables.Add("MyDataTable")

Dim str = "select DocNum,filler 'From Location' ,ItemCode,dscription 'Description',Quantity,whscode 'To Location' from owtr a, wtr1 b where a.docentry=b.docentry and comments like 'Posted From Inward Inspection%' and ref2='" & oDBDSHeader.GetValue("DocNum", 0) & "' "

oForm.DataSources.DataTables.Item(0).ExecuteQuery(str)

oGrid.DataTable = oForm.DataSources.DataTables.Item("MyDataTable")

' Set columns size

oGrid.Columns.Item(0).Width = 50

oGrid.Columns.Item(1).Width = 60

oGrid.Columns.Item(2).Width = 130

oGrid.Columns.Item(0).Editable = False

oGrid.Columns.Item(1).Editable = False

oGrid.Columns.Item(2).Editable = False

oGrid.Columns.Item(3).Editable = False

oGrid.Columns.Item(4).Editable = False

oGrid.Columns.Item(5).Editable = False

oForm.Visible = True

oGrid.Columns.Item(0).Type = SAPbouiCOM.BoGridColumnType.gct_EditText

ocol = oGrid.Columns.Item(0)

ocol.LinkedObjectType = 67

End If

End Sub

but i got error in this line

oForm = oApplication.Forms.AddEx(CP)

Regards,

Anitha