How to Backup and Restore MS Access Database Using VB.Net

Backup and restore are very important just in case you deleted something in the records that are needed in the system. So in this tutorial, I will teach you how to Backup and Restore MS Access Database Using VB.Net. With this method you can backup the file and restore it with ease. Just follow the steps below. Before we proceed, put your Microsoft Access database inside the Debug folder in the project folder. BackupRestoreAccess\BackupRestoreAccess\bin\Debug

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application. ms_1021

Step 2

Add two Buttons and OpenFileDialog the do the Form just like shown below ms_102121

Step 3

Double click the “Backup” button to fire the click event handler of it and do the following code to backup your database file.
  1. Try
  2.             'set the destination and a file name with the date and time
  3.             Dim backupfiledestination As String = Application.StartupPath & "\dbtest" & Format(Now(), "yyyy-M-d H m s") & ".accdb"
  4.             'location of the database file that you want to backup
  5.             Dim databaseFile As String = Application.StartupPath & "\dbtest.accdb"
  6.  
  7.             'create a backup by using Filecopy Command to copy the file from  location to destination
  8.             FileCopy(databaseFile, backupfiledestination)
  9.             MsgBox("Database Backup has been Created Successfully!")
  10.         Catch ex As Exception
  11.             'catch an error  
  12.             MsgBox(ex.Message)
  13.  
  14.         End Try

Step 4

Go back to the design view and double click the “Restore” button to fire the click event handler of it. Do the following code to restore your database file.
  1. Try
  2.             'set a your database file
  3.             Dim restorefile As String = Application.StartupPath & "\dbtest.accdb"
  4.             'declare a variable for storing the text message.
  5.             Dim msgText As String
  6.             'filtering the file
  7.             OpenFileDialog1.Filter = "Access | *.accdb"
  8.             'open the file directory
  9.             If OpenFileDialog1.ShowDialog = DialogResult.OK Then
  10.                 'set a text message
  11.                 msgText = "Are you sure you want to restore your database? It will overwite your database since the backup have made."
  12.                 'validate if you want to restore or not
  13.                 If MessageBox.Show(msgText, "Restore", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.OK Then
  14.                     'restore your database
  15.                     FileCopy(OpenFileDialog1.FileName, restorefile)
  16.                     MsgBox("Database has been restore")
  17.                 End If
  18.             End If
  19.  
  20.         Catch ex As Exception
  21.             MsgBox(ex.Message)
  22.         End Try
The complete source code is included. You can download it and run it on your computer. For more question about this article. You can contact me @ Email – [email protected] Mobile No. – 09305235027 – TNT FB Account – https://www.facebook.com/onnaj.soicalap

Add new comment