Hi Everyone:
I’ve created an application (ODB) with a macro that automatically runs when the application is opened: the macro hides the BASE GUI, prompts the user to enter login details that addresses a remote PostgreSQL Database, and then waits for the user to complete his/her work via an open form. When the user closes the form, a flag is switched that closes the application, so the user is supposed never to see the BASE back end.
I’m using Windows 11, as most of the users will be doing. All the relevant macros are stored with the ODB.
This works fine the first time through, and when the application is closed, no LibreOffice apps or background processes are left running in memory. When I try to run the application for a second time though (without rebooting the device etc.), either the BASE back end screen shows with access to the application’s associated macros lost and BASE still running, or the application simply hangs…
Is this behaviour caused by the way I close the application, or is it something else? I’ve tried every which way to close it but always with a simiar result. I’ve followed procedures for closing using discussions on this site ( 49147 ), (17036 ). Currently my code looks like:
Sub CloseBase
'this routine triggers the Close event for Base/LO to ensure a clean exit when the form is closed
'This is controlled through a global variable (keepAppRunning)
Dim oDesktop As Object
Dim oFrame As Object
Dim oDispatch As Object
Dim oConnection As Object
oDesktop = createUnoService("com.sun.star.frame.Desktop")
oFrame = oDesktop.getCurrentFrame()
’ Option to close any connection though I understand this may not be required
IF ThisComponent.CurrentController.isConnected() THEN
oConnection = ThisComponent.CurrentController.ActiveConnection
'disconnect the connection...
oConnection.Close()
END IF
' Option 1 Close current component.
ThisComponent.close(true)
WAIT 400
' Option2 Close all documents and exit LibreOffice
oDesktop.terminate()
' Option3 Close the current document and potentially exit if it's the last one
' oDispatch = createUnoService("com.sun.star.frame.DispatchHelper")
' oDispatch.executeDispatch(oFrame, ".uno:Quit", "", 0, Array())
End Sub
This closes the application correctly and continues to work as expected until I attach the custom macro for Document Open; after that the app stops functioning the second time it is opened.
I’d be grateful for any guidance on this matter! I’m so close to finishing…
Best Wishes
CB