Date: prev next · Thread: first prev next last
2018 Archives by date, by thread · List index

Hi Peter,

here the macro for saving data while opening or running Base:

SUB DatabaseBackup(inMax AS INTEGER)
        REM A copy of the databasefile *.odb would be created in the
        REM The amount is limited to 5 copies. After it has reached 5 copies,
the oldest copy would be replaced by the new copy.
        REM This procedure doesn't solve the problem, that input of data in the
opened HSQLDB-database couldn't be solved.
        REM Data of the internal HSQLDB were written in the *.odb-file, when
the file will be closed.
        REM The procedure "WriteDataFromCache" helps to write the data into the
opened *.odb-file.
        DIM oPath AS OBJECT
        DIM oDoc AS OBJECT
        DIM sTitel AS STRING
        DIM sUrl_Target AS STRING
        DIM sUrl_Start AS STRING
        DIM i AS INTEGER
        DIM k AS INTEGER
        oDoc = ThisComponent
        sTitel = oDoc.Title     'Name of the document, for example
        sUrl_Start = oDoc.URL   'Path to the title
        oPath = createUnoService("")
        FOR i = 1 TO inMax + 1
                IF NOT FileExists(oPath.Backup & "/" & i & "_" & sTitel) THEN
                REM Saved in the backup-path of the database-user of LO, beginning
with the number, followed by a underscore and the title of the database.
                        IF i > inMax THEN       
                        REM If i bigger than 5, 5 backupcopies do exist. Now we have to look,
which copy is the oldest.
                                FOR k = inMax -1 TO 1 STEP -1
                                        IF FileDateTime(oPath.Backup & "/" & k & "_" & sTitel) <=
FileDateTime(oPath.Backup & "/" & k+1 & "_" & sTitel) THEN
                                        REM File with number 4 must be created before number 5. If 
this is
right, searchung is going on.
                                        REM Searching begins with 4, counting downward. The number 
matched with the number raised by one.
                                        REM If 1 is reached and created before 2, 1 would be 
replaced by
the new copy.
                                                IF k = 1 THEN
                                                        i = k
                                                        EXIT FOR
                                                END IF
                                        REM If a number of a file is found, where the file is 
created later
as the file with the number raised by one, the file with the number
raised by one would be replaced.
                                                i = k+1
                                                EXIT FOR
                                        END IF
                        END IF
                        EXIT FOR
                END IF
        sUrl_Target = oPath.Backup & "/" & i &"_" & sTitel
        REM The path for the targetfile is created and the document will be
copied to this targetfile.

SUB WriteDataFromCache
        REM Writes data of the opened HSQLDB-database while running Base
directly to the harddrive.
        DIM oData AS OBJECT
        DIM oDataSource AS OBJECT
        oData = ThisDatabaseDocument.CurrentController
        IF NOT ( oData.isConnected() ) THEN oData.connect()
        oDataSource = oData.DataSource

SUB BackupNow

SUB BackupAtStart


You could also download it from here:

If you start the macro while opening the database (view created) you
have to use the sub BackupAtStart.
If you start the macro while using the database (have opened any table,
created new rows ...) you should start BackupNow. It will first save all
data in the *.odb-file and afterwords save the database to the
backup-folder of LO.


LibreOffice Community:

To unsubscribe e-mail to:
Posting guidelines + more:
List archive:
All messages sent to this list will be publicly archived and cannot be deleted


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.