BackUp database with a button click

Grafix

Member
Joined
Sep 13, 2006
Messages
10
Location
Singapore
Programming Experience
Beginner
Hi gyz,

Am newbie in VB.NET platform, i created windows application with MS Access back-end database.

Now, i want the user to click a button from window form that will automatically copy the database from its original location to a removable media (or even C:\ drive).

I googled this n found the following code::D

VB.NET:
Try
            Dim sDBFile As String = "C:\MyDBFolder\db1.mdb"
            Dim sBackUpFile As String = "C:\MyDBFolder\BackUp"
            If Not System.IO.Directory.Exists(sBackUpFile) Then
                System.IO.Directory.CreateDirectory(sBackUpFile)
            End If
            sBackUpFile &= "\db1BackUp.mdb"

            'First check the file u want to compact exists or not
            If File.Exists(sDBFile) Then
                Dim db As New DAO.DBEngine
                'CompactDatabase has two parameters, creates a copy of compact DB at the Destination path
                db.CompactDatabase(sDBFile, sBackUpFile)
            End If
            'restore the original file from the compacted file
            If File.Exists(sBackUpFile) Then
                File.Copy(sBackUpFile, sDBFile, True)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

When i paste it in the event i wanna trigger it, it underlined
VB.NET:
DAO.DBEngine
with a tooltip sayin "Type 'DAO.DBEngine' not Defined.":confused:

I then imported the following:

VB.NET:
Imports Util
Imports HRMS
Imports System.IO
Imports Microsoft
Imports std
Imports CrystalDecisions

none of them solves the problem.:eek:

help me out please. tnx:cool:
 
I use the JRO dll file for compacting an repairing Access DB's (haven't found a better solution yet)

"Interop.JRO.dll" I can send you the 9 KB dll file in a PM if you're interested

As for using either JRO or DAO, you need to add a reference to the dll in your vb project, in your solution explorer: right click 'References' then click 'Add Reference' now browse your hdd to the dll file
 
great Brotha, glad to hear that.

Send via my private mail n please to avoid redundant reply can you place the code for me, my database is located in C:\Program Files\HRMS\HRMS.mdb

tnx
 
I forgot that PM's don't support sending of files.

I uploaded a zip file containing:
Interop.JRO.dll, Interop.ADODB.dll, and AccessDB.vb file of which I use to manipulate Access DB's (it's written in VS 2003)

Link removed, file no longer hosted
 
Back
Top