Clean closedown of LibreOffice when Form closes

Hello,

Before going too far, this is confusing:

The usage I expect of this application is that on a particular website

Base is not Internet oriented. Do not comprehend your expectation using Base on a website. Previous questions have dealt with using a connection to a Lubuntu or Windows server and not the Internet. Entirely different situation.

Also, when referencing other questions/answers, please provide an actual link not just a reference.

Thank You.

It would actually be best if you presented a description of what the entire process is - who and how. Disclosing piece by piece causes a lot of duplicate effort.

For example, if you don’t want a “user” to have the Base file open, you can use a Writer document. See this post → Standalone Forms / Switchboard

I have provided the links in the original text, and added a full explanation of what I am trying to do at the end of the original text above

As noted in my comment, Base is not “Web” oriented. Anyone accessing your data will do it using an IP and not the browser. Also they need to have LO installed on their system along with your specific form and queries if designed that way. They connect to your server to get the data and nothing else.

All this about closing everything is in the hands of the user. Only item on your part is if someone is connected to the server accessing the data. You simply have the database.

Wow, that is most unfortunate, I seem to have made a fundamental design mistake, requiring a serious rethink.
I would though like to at least make my application available as a stand-alone program that can run on a PC.
So to do that, I still need to solve the questions listed at the beginning of this post.

Assume a stand-alone PC, a non-expert user of the program, who clicks on a button and runs my .odb.
Using the Sample 2 example posted by Mr Ratslinger (link), the LibreOffice GUI disappears but leaves the Form running, which the user can utilise. This is what I want.
But Ratslinger says:
"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->
Can a macro be written to do this automatically when the form is closed “brutally”, for example by pressing the X in the top right hand corner?

Have you looked at the link provided in the earlier comment? That is essentially running a form without opening the .odb and not needing to worry about closing a hidden version.

Simple way to go.

No, as it talked about a Writer document, which did not seem to be my case. I’ll look at it now, thanks

Yes that is correct. You may not realize this but a Base form is basically a Writer document. You can use a Writer document as a form connected to a Base file. The actual .odb need not be opened. This makes it fit in with your request.

Hi, unfortunately in my case the solution proposed using Writer does not work, due to the fact that my Form uses macros. So I am back to my original question: is it possible to write a macro to cleanly close Base when using the Sample 2 described by Ratslinger?

Not sure why that is a problem. Have used macros in standalone forms many times.

Edit:

Have removed suggested code as further testing with the hidden Base files does create problems.

Concerning the standalone Forms, which do seem the cleanest solution, and your observation that you have used macros in standalone forms many times, it seems strange that in my case the Form doesn’t work. First of all I got errors that it didn’t find the macro(s). So I copied and pasted the macros into the Form. Now it just doesn’t find any data, so probably it is not connecting to the database. I have tried going back to an old version with an embedded database, to see if that helps, but it still doesn’t find the data.

Sorry to keep posting, I may have found the solution, by manually speicfying the .odb file file as the source. Watch this space!

ok, getting there, the key is to specify the .odb file as the Data Source for all the forms and subforms. The standalone Form will though not work with the temporary tables, as the Form cannot find them in the .odb file, even if they are there! The Form also prompts me for the password to connect to the Firebird databases, so the connect_to_database macro will need looking at. So it looks to me that if I want a standalone form I will need to go back to a permanent file tbl_SrchValues to exchange data (no problem as the Form will be standalone) and to an embedded database (again no problem for the standalone Form).

Hello,

This seems to work OK although I prefer to use the standalone forms.

Create a global variable:

global Continue as boolean

At the beginning of the Sub ‘HideDBWinOpenSwitchboard’ add:

Continue = true

Just before the end of the Sub ‘HideDBWinOpenSwitchboard’ add:

do while Continue
	wait 20
loop
ThisComponent.close(true)

Add this sub:

Sub CloseBase
    Continue = false
End Sub

and link it to the Document Closed event of the form you are dealing with.

When that form is closed it will close that Base file.

Also,

Can all the code that follows be safely excluded in my case?

No. That is code to open the specific form. You must specify your form to be opened there. Of course, the commented lines can be eliminated.

Hi, I have tried the code you suggest, but on my Form it crashes LibreOffice: the Form comes up and shows the correct initialisation, but then will not respond to any input, and it crashes. If I comment out your “do while loop” then it works normally. So having a loop active in the Open Document event in my case does not seem to be a solution. I will try your suggestion of eliminating the temporary hidden table and see if that works.

Isn’t there anything that can be done just by invoking the “Document Closed” event? Thanks

Have tested this process without problem as you note. Would need to see the code you actually used.

Isn’t there anything that can be done just by invoking the “Document Closed” event? Thanks

No as the functions for the code needed is not available since the form is closed. And if done before actually closing the form it causes other problems such as crashing Base.

I have added the macro code into the original question above. It is 99% the same as yours.
By the way, I have nearly got the standalone Form to work now, just having a few problems with the emporary tables and connecting to the Firebird database (see comments just before your Answer above)

Have tested with one of your forms and your posted code. Have no problems. However, with further checking, although it completely closes the open Base file, LO is still open. A complete shutdown is not possible as there is a problem with that. See → Clean exit macro from DB and LibO ?.

I have not seen an easy solution. Here is one presented by killing the task with a shell command →
Re: Closing OpenOffice by macro

May someday test this but would need to set up a separate install to prevent damage to the system in event of problems.

OK so someday was today. This (for Linux Ubuntu 18.04):

Shell "killall soffice.bin"

just before End Sub of HideDBWinOpenSwitchboard will remove the remainder of LO. However you must understand that any LO items currently open (at this point the Base file is already closed) will be killed and can damage the files.

You can test the killall command in a terminal session.