How to Backup and Restore MS Access Database Using VB.Net
Submitted by janobe on Wednesday, September 5, 2018 - 13:26.
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.
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
BackupRestoreAccess\BackupRestoreAccess\bin\Debug
Step 1
Open Microsoft Visual Studio 2015 and create a new windows form application.
Step 2
Add two Buttons and OpenFileDialog the do the Form just like shown below
Step 3
Double click the “Backup” button to fire theclick event handle
r of it and do the following code to backup your database file.
- Try
- 'set the destination and a file name with the date and time
- Dim backupfiledestination As String = Application.StartupPath & "\dbtest" & Format(Now(), "yyyy-M-d H m s") & ".accdb"
- 'location of the database file that you want to backup
- Dim databaseFile As String = Application.StartupPath & "\dbtest.accdb"
- 'create a backup by using Filecopy Command to copy the file from location to destination
- FileCopy(databaseFile, backupfiledestination)
- MsgBox("Database Backup has been Created Successfully!")
- Catch ex As Exception
- 'catch an error
- MsgBox(ex.Message)
- End Try
Step 4
Go back to the design view and double click the “Restore” button to fire theclick event handler
of it. Do the following code to restore your database file.
- Try
- 'set a your database file
- Dim restorefile As String = Application.StartupPath & "\dbtest.accdb"
- 'declare a variable for storing the text message.
- Dim msgText As String
- 'filtering the file
- OpenFileDialog1.Filter = "Access | *.accdb"
- 'open the file directory
- If OpenFileDialog1.ShowDialog = DialogResult.OK Then
- 'set a text message
- msgText = "Are you sure you want to restore your database? It will overwite your database since the backup have made."
- 'validate if you want to restore or not
- If MessageBox.Show(msgText, "Restore", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.OK Then
- 'restore your database
- FileCopy(OpenFileDialog1.FileName, restorefile)
- MsgBox("Database has been restore")
- End If
- End If
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try
Add new comment
- 3107 views