Ask Your Question

Clean exit macro from DB and LibO ? [closed]

asked 2017-02-18 10:07:15 +0200

kirsch gravatar image

updated 2020-09-25 12:35:34 +0200

Alex Kemp gravatar image

Hello, is There a usable macro on hand, to trigger from a button in a Base Form, a clean exit from DB and LibO(V5) ? I'll take it ! Bob

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-09-25 12:36:06.809159


This button exists… its the X button in the up|right corner of the window

karolus gravatar imagekarolus ( 2017-02-18 14:02:17 +0200 )edit

2 Answers

Sort by » oldest newest most voted

answered 2017-02-19 02:02:49 +0200

Ratslinger gravatar image

updated 2017-02-21 21:28:22 +0200

Understand that Ctrl & Q closes ALL open instances of LO and not just your .odb - including any writer, calc, math, draw, or impress windows which are open. With that, here is the function:

sub loQuit
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("")
    dim args1(0) as new
    dispatcher.executeDispatch(document, ".uno:Quit", "", 0, args1())
end sub

Edit: This may work to just close the .odb and related open form:

sub CloseDoc
    document = ThisComponent.getParent().getCurrentController().getFrame()
end sub

Edit 2/21/2017:

Further testing was done using the above routines. All tests were done on Linux systems.

Sub "loQuit" works without a problem in LO v5.3.0.3 but using v5.2.3.3 there is an abnormal exit when the routine is called from a push button or custom toolbar item. It does work in v5.2.3.3 when run directly from Basic IDE.

Sub "CloseDoc" executes from a push button in v5.3.0.3 and v5.2.3.3 but does not completely shut down LO. Ironically, under both versions, if the document.close(1) statement is actually executed within MRI, there is a complete shutdown without any side effects. There is no explanation for this at this point and it is not the first time I saw this type of thing happen. The other occurrence has eluded me for over a year.

edit flag offensive delete link more


The above "LoQuit code

  • gives" an UNEXPETED ERROR on activating the macro from a QUIT LIBREOFFICE button in the Form!
  • and leaves a .lck file in the DB directory.

So I deactivate the button and label it with "quit with CRTL/Q" ;-)

kirsch gravatar imagekirsch ( 2017-02-21 17:30:54 +0200 )edit

@kirsch Will edit my answer with further findings/explanation.

Ratslinger gravatar imageRatslinger ( 2017-02-21 21:10:05 +0200 )edit

answered 2017-02-19 00:34:25 +0200

kirsch gravatar image

updated 2017-02-19 00:37:47 +0200

Hi Karolus, about your comment

That upper right corner "X" button does not the job properly in my case:

I start the database by opening a Form from start, the usual DB development window is not on screen (hidden). When I click the X button in the Form, the form-window closes leaving a LibreOffice process running! And it gives trouble later on when I try to start a other DB. Closing that Form trough its menu File->Close does the un-clean exit and leaves a unneeded and unwanted LibreOffice running process.

The only clean Exit from that is using in the Form the menu choice File->Quit LibreOffice (Of course it needs the menu bar in the Form) or I can use CTRL/Q to quit LibO.

But in my application, I'd like to have a nice button in the form to do that CTRL/Q action.

Thanks anyway for your comment Karolus, it makes me explain my problem more pecisely. Bob.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-02-18 10:07:15 +0200

Seen: 812 times

Last updated: Feb 21 '17