Auto Save Database for Libreoffice Base

I create a database and it form in libreOffice base. I want an auto save macro on form, which automatically run after 5 minutes and save changes made on the form. And macro run every 5 min. How can i achieve that?

If you really want to get a save database: Don’t use internal database. This database will only be written back to the *.odb-file when closing the *.odb-file. Use a connection to a Firebird file instead.

For saving a form automatically you could try it with a

GLOBAL boStop AS BOOLEAN

SUB StartSaving(oEvent AUS OBJECT)
   oForm = oEvent.Source
   boStop = false
   DO 
      WAIT 300000  (Update).
      IF oForm.isNew THEN
         oForm.insertRow()
      ELSE
         oForm.updateRow()
      END IF
   LOOP WHILE  boStop = false
END SUB

SUB StopSaving
   boStop = true
END SUB

Macro should start when loading the form. Don’t forget connect StopSaving when form will be closed.

1 Like

Thanks, I will try that approach.

This setup will ensure that your form is saved automatically every 5 minutes.

Sub AutoSaveForm
    Dim oForm As Object
    Dim oDoc As Object

    oDoc = ThisComponent
    oForm = oDoc.Drawpage.Forms.getByName("YourFormName") 

    oDoc.getCurrentController().getFrame().getContainerWindow().commit()

    
    Application.OnTime Now + TimeValue("00:05:00"), "AutoSaveForm"
End Sub