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
Backup-folder.
        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
Media_with_Macros.odb
        sUrl_Start = oDoc.URL   'Path to the title
        oPath = createUnoService("com.sun.star.util.PathSettings")
        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 
is
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
                                        ELSE
                                        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
                                NEXT
                        END IF
                        EXIT FOR
                END IF
        NEXT
        sUrl_Target = oPath.Backup & "/" & i &"_" & sTitel
        REM The path for the targetfile is created and the document will be
copied to this targetfile.
        FileCopy(sUrl_Start,sUrl_Target)
END SUB

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
        oDataSource.flush
END SUB

SUB BackupNow
        WriteDataFromCache
        DatabaseBackup(10)
END SUB

SUB BackupAtStart
        DatabaseBackup(10)
END SUB

--------------------------------

You could also download it from here:
http://robert.familiegrosskopf.de/lo_hb_en/Media_with_Macros.odb

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.

Regards

Robert
-- 
Homepage: http://robert.familiegrosskopf.de
LibreOffice Community: http://robert.familiegrosskopf.de/map_3


-- 
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Context


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.