Page 1 of 1

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

Posted: Fri May 17, 2019 3:21 pm
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?

Re: Finish a Loop when closing form(window)

Posted: Fri May 17, 2019 9:49 pm
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?

Re: Finish a Loop when closing form(window)

Posted: Fri May 17, 2019 10:32 pm
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.

Re: Finish a Loop when closing form(window)

Posted: Sat May 18, 2019 12:13 am
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

Re: Finish a Loop when closing form(window)

Posted: Sat May 18, 2019 12:29 am
by dvd251996
That works like a charm. Thank you a lot!