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

Keyboard macros or custom scripts

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

Postby dvd251996 » Fri May 17, 2019 3:21 pm

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   Expand viewCollapse view
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
dvd251996
 
Posts: 3
Joined: Fri May 17, 2019 3:14 pm

Re: Finish a Loop when closing form(window)

Postby UnklDonald418 » Fri May 17, 2019 9:49 pm

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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1122
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Finish a Loop when closing form(window)

Postby dvd251996 » Fri May 17, 2019 10:32 pm

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
dvd251996
 
Posts: 3
Joined: Fri May 17, 2019 3:14 pm

Re: Finish a Loop when closing form(window)

Postby UnklDonald418 » Sat May 18, 2019 12:13 am

Try adding an error handler
Near the beginning of the macro something like
Code: Select all   Expand viewCollapse view
On Error GoTo Error1

then after the Loop statement, just before End Sub add
Code: Select all   Expand viewCollapse view
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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1122
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Finish a Loop when closing form(window)

Postby dvd251996 » Sat May 18, 2019 12:29 am

That works like a charm. Thank you a lot!
Libreoffice 6.2.3.2 on Windows 10
dvd251996
 
Posts: 3
Joined: Fri May 17, 2019 3:14 pm


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 2 guests

cron