Have the installer include the .MDB file along with your other files in the same program folder.
Example, the user states in the installer that they want to install the software to C:\Program Files\Company\Software\; so with that, the installer copies the software files, but also a backup copy of the .MDB file - maybe in the path C:\P...\Software\data\orginialdatabase.mdb
The reason for this, is that it will work with the following code - which you can incorporate in to your project in the Form_Load procedure on the MAIN form:
VB.NET:
Private Sub Form_Load()
Dim Directory As String = "C:"
'Check to see if the database exists.
If Not My.Computer.FileSystem.FileExists(Directory & "\database.mdb") Then
MsgBox("The database could not be found. The application will now replace a backup of the database.")
FileCopy(Application.StartupPath & "\data\database.mdb", Directory & "\database.mdb")
Else
MsgBox("The database was found: " & Directory & "\database.mdb")
End If
'INCLUDE HERE, OTHER FORM_LOAD CODE.
So here, you are using both a backup copy and an actual copy. Another addition to your software is that you could have the application, on exit, save a backup copy of the database just in case something goes wrong:
VB.NET:
Private Sub Form_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim outFileName As String = "db_backup_" & Format(Date.Now, "ddMMyy_HHmm") & ".mdb"
FileCopy(Directory & "\database.mdb", Application.StartUpPath & "\data\backups\" & outFileName)
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.