Skip to Content
author's profile photo Former Member
Former Member

UI: Company Changed Event

Hi all.

Can anyone provide me with an example on how to handle the Company Changed event?

What I do now is something like this (the SetApplication works when I connect in the first place):

Dim sConnectionString As String

Dim SboGuiApi As SAPbouiCOM.SboGuiApi

Private Sub con_AppEvent(ByVal EventType As SAPbouiCOM.BoAppEventTypes) Handles SBO_Application.AppEvent

Select Case EventType

Case SAPbouiCOM.BoAppEventTypes.aet_ShutDown


Case SAPbouiCOM.BoAppEventTypes.aet_CompanyChanged

vcmp = Nothing


End Select

End Sub

Sub SetApplication()

Dim str as string


SBO_Application = SboGuiApi.GetApplication()

vcmp = New SAPbobsCOM.Company()

str = vcmp.GetContextCookie()

str = SBO_Application.Company.GetConnectionContext(str)



. . .

end Sub

The problem is, that I keep getting the CompanyChanged event. My guess is that it is because I reconnect to the application before the eventhandler has returned, but I can't really figure out how to do....

Any help appriciated.

Thanks in advance

Jesper Carstensen

Add comment
10|10000 characters needed characters exceeded

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on May 05, 2004 at 02:37 PM

    Hi Jesper

    We did it like that and it is working well.

    Special hint: our procedure "RunSboChecked"; it returns a catchable VB.NET error in place of a non-catchable SBO error value.

    Private Sub mwuiApp_AppEvent( _

    ByVal EventType As SAPbouiCOM.BoAppEventTypes) Handles mwuiApp.AppEvent

    Select Case EventType

    Case SAPbouiCOM.BoAppEventTypes.aet_ServerTerminition, _


    Me.mwuiApp = Nothing

    Me.muiApi = Nothing

    Me.mdiCmp = Nothing




    Case SAPbouiCOM.BoAppEventTypes.aet_CompanyChanged

    Me.mdiCmp = Nothing

    Me.mdiCmp = New SAPbobsCOM.Company

    Call Me.subConnectToDI()

    End Select

    End Sub

    Public Sub subConnectToDI()

    Call Me.subSetConnectionContext()

    Call Me.subConnectToCompany()

    mstrServer = mdiCmp.Server

    mstrCompanyDB = mdiCmp.CompanyDB

    mstrSboUser = mdiCmp.DbUserName

    End Sub

    Private Sub subSetConnectionContext()

    Dim strCookie As String

    Dim strConnectionContext As String


    '// Acquire the connection context cookie from the DI API.

    strCookie = mdiCmp.GetContextCookie

    '// Retrieve the connection context string from the UI API using the

    '// acquired cookie.

    strConnectionContext = mwuiApp.Company.GetConnectionContext(strCookie)

    '// Set the connection context information to the DI API.


    Catch ex As Exception

    Call subBeenden(ex, "Die zur Verbindung mit der Datenbank nötigen Informationen konnten " _

    & "nicht ermittelt werden.")

    End Try

    End Sub

    Private Sub subConnectToCompany()


    '// Establish the connection to the company database.


    Catch ex As Exception

    Call subBeenden(ex, "Die Verbindung zur Datenbank konnte nicht hergestellt werden.")

    End Try

    End Sub

    Public Sub RunSboChecked(ByVal intSboReturnValue As Integer)

    If intSboReturnValue = 0 Then

    'everything ok, no SBO error


    Dim intError As Integer

    Dim strError As String

    mdiCmp.GetLastError(intError, strError)

    strError = "SBO error " & CStr(intError) & ": " & strError

    Throw New Exception(strError)

    End If

    End Sub

    Add comment
    10|10000 characters needed characters exceeded