A Simple Backup and Restore Microsoft Access Database Using Visual Basic.Net [Part I]
Submitted by joken on Tuesday, November 4, 2014 - 08:05.
This tutorial, i'm going to show you how to create a simple way on how to create an application that will of enable you to create a Backup of your Microsoft Access Database using Visual Basic.Net. To start in this application, Create a new project in Visual Basic and Name it as “dbBackup”. Then add three buttons, Textbox, three Labels. And arrange all objects that looks like as shown below.
Next step, from the toolbox, add OpenFileDialog and name it as “OFD” then add also a SaveFileDialog then name it as “SFD”. After designing the user interface, we are now ready to add functionality to our application. To do this, double click the form and add the following code:
Next, double click also the browse button, and add the following code:
The following code below will simply used to select a specific Microsoft Access database file and set the location to the Textbox provided.
And we need also to add code to check if the textbox is empty, and if empty it will disable the Backup button, double click the textbox and here’s the following code:
And finally add the following code for Back up button.
then press F5, and test your application.
Just follow the link if you want to download the Complete Source Code.Click here.
- 'Set the backup button as disabled
- btnbackup.Enabled = False
- Try
- 'set the Title of a Openfolder Dialog Box
- OFD.Title = "Please MS Access Database File"
- 'Set a specific Filter and Index
- OFD.Filter = "MS Access Database Files (*.mdb)|*.accdb"
- OFD.FilterIndex = 1
- ' when the Browse Image button is click it will open the OpenfileDialog
- 'this line of will check if the dialogresult selected is cancel then
- If OFD.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
- 'Set the location
- txtlocation.Text = OFD.FileName
- End If
- Catch ex As Exception
- 'catch some error that may occur
- End Try
- ' it Disable the Backup button when the location is empty else do the opposite
- If txtlocation.Text = "" Then
- btnbackup.Enabled = False
- Else
- btnbackup.Enabled = True
- End If
- Try
- 'call the SavefileDialog box
- SFD.ShowDialog()
- 'Set the title
- SFD.Title = "Save File"
- 'Set a specific filter
- SFD.Filter = "(*.mdb)|*.accdb"
- If SFD.ShowDialog = Windows.Forms.DialogResult.OK Then
- 'set the destination of a file
- txtDestination.Text = SFD.FileName
- Dim portfolioPath As String = My.Application.Info.DirectoryPath
- 'create a backup by using Filecopy Command to copy the file from location to destination
- 'Reload the form
- Call Form1_Load(sender, e)
- txtlocation.Text = Nothing
- txtDestination.Text = "Destination..."
- End If
- Catch ex As Exception
- 'catch some error that may occur
- End Try
Add new comment
- 595 views