Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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("com.sun.star.frame.DispatchHelper")
    dim args1(0) as new com.sun.star.beans.PropertyValue
    dispatcher.executeDispatch(document, ".uno:Quit", "", 0, args1())
end sub

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("com.sun.star.frame.DispatchHelper")
    dim args1(0) as new com.sun.star.beans.PropertyValue
    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.CurrentController.Model.Parent
    document.close(1)
end sub

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("com.sun.star.frame.DispatchHelper")
    dim args1(0) as new com.sun.star.beans.PropertyValue
    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.CurrentController.Model.Parent
ThisComponent.getParent().getCurrentController().getFrame()
    document.close(1)
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.