[Solved] Finish a Loop when closing form (window)

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
dvd251996
Posts: 4
Joined: Fri May 17, 2019 3:14 pm

[Solved] Finish a Loop when closing form (window)

Post by dvd251996 »

This should be really easy but I can't find it out. Im trying to do a loop for saving the form records(on a base) every minute. Which works but when I close the form the macro keeps running and eventually returns a unwanted error because form is no longer open:
BASIC runtime error.
An exception occurred
Type: com.sun.star.lang.DisposedException
Message: Frame disposed.
This is my macro

Code: Select all

Sub Save_loop
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

   Do While '???Window is open
       dispatcher.executeDispatch(document, ".uno:RecSave", "", 0, Array())
       wait 60000
   Loop
End Sub
What can I put on the While/Until for not returning this error?
Last edited by dvd251996 on Sat May 18, 2019 12:30 am, edited 1 time in total.
Libreoffice 6.2.3.2 on Windows 10
UnklDonald418
Volunteer
Posts: 1547
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Finish a Loop when closing form(window)

Post by UnklDonald418 »

Where are you storing the macro?
I stored it in the document and in my tests the macro stopped when the document was closed.

Instead of the macro why not set Tools>Options>Load/Save>General Save AutoRecovery information every ... to 1 minutes?
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
dvd251996
Posts: 4
Joined: Fri May 17, 2019 3:14 pm

Re: Finish a Loop when closing form(window)

Post by dvd251996 »

Im storing the macro at the document, and I also tried in My macros and got same error. The error comes when I close the window of the form, not the document.

And the option of AutoRecovery doesn't seem to work to me. Im not sure why, but probably because I have the tables in a external base and that option only saves the document.
Libreoffice 6.2.3.2 on Windows 10
UnklDonald418
Volunteer
Posts: 1547
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Finish a Loop when closing form(window)

Post by UnklDonald418 »

Try adding an error handler
Near the beginning of the macro something like

Code: Select all

On Error GoTo Error1
then after the Loop statement, just before End Sub add

Code: Select all

Error1: Exit Sub
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
dvd251996
Posts: 4
Joined: Fri May 17, 2019 3:14 pm

Re: Finish a Loop when closing form(window)

Post by dvd251996 »

That works like a charm. Thank you a lot!
Libreoffice 6.2.3.2 on Windows 10
Post Reply