Backup progressivi.

Anonimo
2017-08-26T20:37:37+00:00

Ciao,

facendo una ricerca in rete sono riuscito ad adattare il seguente codice per creare il backup del database.

In un modulo:

Declare PtrSafe Function apiCopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long

Sub CopyFile(SourceFile As String, DestFile As String)

       '---------------------------------------------------------------

       ' PURPOSE: Copy a file in use on disk from one location to another.

       ' ACCEPTS: The name of the source file and destination file.

       ' RETURNS: Nothing

       '---------------------------------------------------------------

       Dim Result As Long

         If Dir(SourceFile) = "" Then

            MsgBox Chr(34) & SourceFile & Chr(34) & _

               " is not valid file name."

         Else

            Result = apiCopyFile(SourceFile, DestFile, False)

         End If

End Sub

In un pulsante:

Call CopyFile(CurrentProject.Path & "\Database.mdb", CurrentProject.Path & "\CopiaDatabase.mdb")

Quello che a me servirebbe, è creare ad ogni click del pulsante un backup nuovo, cioè che non si vada a sovrapporre a quello già esistente.

Ad esempio CopiaDatabase1, CopiaDatabase2, CopiaDatabase3 ecc...

Vladimiro

Microsoft 365 e Office | Access | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento

44 risposte

Ordina per: Più utili
  1. Anonimo
    2017-08-28T19:08:49+00:00

    Ciao Francesco e grazie per la tua disponibilità.

    Non so perché, ma mi sovrascrive sempre lo stesso file di backup

    Temp_Database

    Vladimiro

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2017-08-28T17:59:25+00:00

    Per la data ed il nome puoi usare una form, ma perché ti devi complicare la vita? Non puoi usare i valori di sistema? Questo è il mio codice, sicuramente lo si potrà migliorare, ma per me funziona e quindi non perdo tempo a cercare "el fret per el lèt" come si diceva dalle mie parti...

    Public Sub BackupBd()

        On Error GoTo BackupBd_Err

        DoCmd.Hourglass True

        Dim fs, f As Object

        Dim wNewFile As String

        Dim wOldFile As String

        Dim wBckFile As String

        'Copie de la BD

        Set fs = CreateObject("Scripting.FileSystemObject")

       'Backup de l'application

        wNewFile = CurrentProject.Path & "" & "Temp_" & CurrentProject.Name

        wOldFile = CurrentProject.Path & "" & CurrentProject.Name

        wBckFile = CurrentProject.Path & "\Backup" & "Backup_" & Date & "_" & Time & "_" & CurrentProject.Name

        fs.CopyFile wOldFile, wNewFile

        ' Compactage

        Application.CompactRepair LogFile:=True, SourceFile:=wNewFile, DestinationFile:=wBckFile

        Kill (wNewFile)

    GoTo NoBackendAccess (questa parte la saltavo quando avevo il backend su SQL Server. Naturalmente BE e FE devono essere nella stessa directory ed i nomi devono essere standard Pippo.accdb e Pippo_data.accdb)

       'Backup des données

        wNewFile = CurrentProject.Path & "" & "Temp_" & Left(CurrentProject.Name, Len(CurrentProject.Name) - 6) & "_data.accdb"

        wOldFile = CurrentProject.Path & "" & Left(CurrentProject.Name, Len(CurrentProject.Name) - 6) & "_data.accdb"

        wBckFile = CurrentProject.Path & "\Backup" & "Backup_" & Date & "_" & Time & "_" & Left(CurrentProject.Name, Len(CurrentProject.Name) - 6) & "_data.accdb"

        fs.CopyFile wOldFile, wNewFile

        ' Compactage

        Application.CompactRepair LogFile:=True, SourceFile:=wNewFile, DestinationFile:=wBckFile

        Kill (wNewFile)

    NoBackendAccess:

        gMsg = "***** Backup terminé *****"

        MsgBox gMsg, vbExclamation, Application.Name

    BackupBd_Exit:

        DoCmd.Hourglass False

        Exit Sub

    BackupBd_Err:

        MsgErr Err.Number, Err.Description, "mMain", "BackupBd", Application.Name, vbCritical, "Erreur pendant le backup"

        GoTo BackupBd_Exit

    End Sub

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2017-08-28T17:47:34+00:00

    In tal caso basta che aggiungi una msgbox con risposta.

    Ciao Francesco,

    si che c'è l'msgbox, ma come faccio ad inserire data e nome database?

    Cioè, volendo usare il seguente codice (magari se mi fai vedere per intero come fai il backup tu, sarebbe meglio :-) ....)

    Call CopyFile(CurrentProject.Path & "\Database.mdb", CurrentProject.Path & "\CopiaDatabase.mdb")

    Come faccio ad aggiungere la data scritta in una finestra convenzionale a CopiaDatabase?

    Vladimiro

    La risposta è stata utile?

    0 commenti Nessun commento
  4. Anonimo
    2017-08-28T16:57:08+00:00

    In tal caso basta che aggiungi una msgbox con risposta.

    La risposta è stata utile?

    0 commenti Nessun commento
  5. Anonimo
    2017-08-28T16:51:03+00:00

    Ciao Sandro, Francesco e Mimmo.

    Sono riuscito a parlare con la persona interessata facendomi spiegare meglio la sua necessità.

    Quello che gli serve è che alla chiusura del database gli venga richiesto se fare il Backup o meno.

    Nel caso scegliesse di farlo, gli si dovrebbe aprire una finestra per poter scrivere la data ( che poi verrebbe aggiunta al nome del database salvato).

    Vladimiro

    La risposta è stata utile?

    0 commenti Nessun commento