Hi, I wish to
-
automatically open a Form when LibreOffice is run
-
for the LibreOffice GUI to disappear but to leave the form running
-
to clean up LibreOffice when the form is closed
For 1) and 2) I have seen the posts by Ratslinger July 6 2017 (108166) which reference Doug’s answer July 19 2015 to post (53310) by jay Arr.
In Ratslinger’s answer on July 6 2017, he says concerning Sample 2: “IMPORTANT! If you just close the form, the .odb is still active in memory! To Exit properly, use Ctrl & Q keys OR from Instruments menu select File->Exit LibreOffice”.
As the users of my Form will not be proficient in IT or know how to close LibreOffice, is there any way that a macro can be defined to ensure that when the Form is closed, that the cleanup operations recommended by Ratslinger get done automatically?
The usage I expect of this application is that a user will press a button which from his/her point of view will cause my Form to be seen. He/She will not know about LibreOffice and when finished with the Form will somehow close it, by pressing the X icon top right hand of the form. When that happens, I need to ensure that LibreOffice closes down cleanly.
Edit 11 Feb 2020
Here is the Sample 2 macro code used when opening the document, it is 99% the same as that proposed by Ratslinger in his original Sample 2 example from 2017
option explicit
global Continue as Boolean
Sub HideDBWinOpenSwitchboard
' bound to Open Document event
Dim tc As Object
Dim i As Integer
Dim cntrllr As Object
Dim frm As Object
Dim appWindow As Object
Dim comWin As Object
Dim FrmContainer As Object
Dim rootFrm As Object
Dim rootDoc As Object
Dim ctrllt As Object
'added by Ratslinger
Continue = true
REM 'catch any error to give alternate instructions to user'
' On Local Error Goto ErrHandOpenDB
REM 'if applied to the `Open Document` event `ThisComponent` is equivalent to `ThisDatabaseDocument`'
REM 'the difference being `ThisComponent` works'
tc = ThisComponent
REM 'this loop is to work around a delay in defining `ThisComponent` by LO'
i = 1
Do Until InStr(tc.dbg_properties, "CurrentController" ) > 0 Or i >= 70
Wait 5
tc = ThisComponent
i = i + 1
Loop
REM 'work around more LO limitations when atteming to run on `Open Document` event'
' tc.connectController(tc.CurrentController)
tc.Title = "connection_asmedb.odb"
REM 'here is the object hierarchy to get to the database window'
cntrllr = tc.CurrentController
REM 'belt and suspenders, this might not be necessary'
If cntrllr.isConnected = False Then
cntrllr.Connect
End If
REM 'more of the object hierarchy'
frm = cntrllr.Frame
appWindow = frm.ContainerWindow
REM 'make main application window disappear'
appWindow.setVisible(False)
appWindow.IsMaximized = False
REM 'FYI this is the window inside the application window, if can be resized independently'
REM 'but have not seen any use for this yet'
REM comWin = frm.ComponentWindow
REM 'open switchboard form'
FrmContainer = tc.FormDocuments.getByName("frm_SearchArchive")
FrmContainer.open
rootFrm = FrmContainer.Component.getDrawPage.getForms
rootDoc = rootFrm.parent
ctrllr = rootDoc.CurrentController
frm = ctrllr.Frame
REM 'apply title of database set forth above plus title of form'
frm.Title = tc.Title & ": frm_SearchArchive"
REM 'maximize the switchboard window'
' frmWindow = frm.ContainerWindow
' frmWindow.IsMaximized = True
REM 'FYI again here is the window inside the form window'
REM frmComp = frm.ComponentWindow
REM 'adjust zoom of switchboard'
' ctrllr.ViewSettings.ZoomValue = 90
' Exit Sub
' ErrHandOpenDB:
' MsgBox "The intro did not go as planned. Browse to `Forms` and open the `Switchboard`."
' added by Ratslinger
do while Continue
wait 20
loop
ThisComponent.close(true)
End Sub
Sub CloseBase
' bound to Document Closed event
Continue = false
End Sub