OK, i have this Backup module for my system's database.

Now i would like to have a module of restoring and deleting backups of it.

Here's some info:

The backup files created are stored in a Folder named "Backup"

My database has 2 Columns having OLE type objects, Pictures and Fingerprints
from a Biometrics (This part isn't finish yet)

Can you help me with this, code snippet if any.

Googled but codes from other sites is complicated (VERY)

So if you can provide some code snippet, please include some comment lines for instruction.

Thanks.

Now i would like to have a module of restoring and deleting backups of it.

Restoring as in deleting the current database say on the server and then pasting the saved/backed up database?

Fingerprints
from a Biometrics (This part isn't finish yet)

Open a new thread if any questions on biometrics...:)

No sir. What i mean is my whole database would have a backup to a folder Named "Backup"

The folder is also located in the same folder where my program is.

Nah, Biometrics isn't included here, just like saying about it ;)

The backup file extension name is '.bak'

Just don't know how to restore and delete a .bak file

RESTORE - i mean a backup file from previous day can be restored today
DELETE - as in delete the file, cant be restored again.

If you can give some attachment.

To delete a file, you can use the Kill statement, but note that this permanently deletes the file (does not put it in the Recycle Bin) -

Kill "C:\temp\test.bak"

Whatever method you choose (Kill or API) you must check if file exists first or it will fail.
Here are two ways to delete file - one is using Kill statement and second is the API way that sends deleted file to recycle Bin -

Private Sub Command1_Click()
Dim sfile As String

    sfile = "C:\a.txt"
    
    If FileExists(sfile) Then
        Kill sfile
        MsgBox "File's deleted permanently."
    Else
        MsgBox "File you're trying to delete doesn't exist."
    End If

End Sub

Private Function FileExists(file As String) As Boolean
Dim fileLength As Long

On Error Resume Next

    fileLength = -1
    fileLength = FileLen(file)
    
    FileExists = CBool(fileLength > -1)

End Function

Method 2: using API -

Option Explicit

Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_NOCONFIRMATION = &H10

Private Type SHFILEOPSTRUCT
    hwnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAnyOperationsAborted As Long
    hNameMappings As Long
    lpszProgressTitle As Long
End Type

Private Declare Function SHFileOperation Lib _
    "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Private Sub Command2_Click()
Dim sfile As String

    sfile = "C:\test2.txt"
    
    If FileExists(sfile) Then
        If DeleteFile(sfile) Then
            MsgBox "File deleted. Check your recycle bin."
        Else
            MsgBox "File could not be deleted."
        End If
    Else
        MsgBox "File you're trying to delete doesn't exist."
    End If

End Sub

Private Function FileExists(file As String) As Boolean
Dim fileLength As Long

On Error Resume Next

    fileLength = -1
    fileLength = FileLen(file)
    
    FileExists = CBool(fileLength > -1)

End Function

Public Function DeleteFile(file As String) As Boolean
'======================================================
Dim shfo As SHFILEOPSTRUCT
Dim lresult As Long

    With shfo
        .wFunc = FO_DELETE
        .pFrom = file
        .fFlags = FOF_ALLOWUNDO Or FOF_NOCONFIRMATION
    End With
    
    lresult = SHFileOperation(shfo)
    
    DeleteFile = CBool(lresult = 0)

End Function

To restore a file, you need to have another backup in a different file. When deleted, just copy the file over from the different folder and it should be replaced.

Have a look at the attached sample where synchronization is used. This checks to see if the one database is larger than the other and then synchronize them so that the "original" have all the necessary records added.


To restore a file, you need to have another backup in a different file. When deleted, just copy the file over from the different folder and it should be replaced.

I'm going to use Filecopy on that one.

Thanks again sir.

Cool, it was a pleasure Abe.:)

Happy coding.;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.