Results 1 to 4 of 4

Thread: Back-up and restore using DAO,Acces as Database,vb6 application

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2009
    Location
    Manila, Phillippines
    Posts
    54

    Back-up and restore using DAO,Acces as Database,vb6 application

    Hello.. I need your expertise,

    I am using the component DAO 3.6 in VB 6.0 and Access 2003 as Database, Can anyone know the code on how to back up and restore my data in my application?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Back-up and restore using DAO,Acces as Database,vb6 application

    Moved From The CodeBank (which is for posting finished code to be shared as opposed to asking questions)

  3. #3
    Lively Member
    Join Date
    Apr 2007
    Location
    Gold Coast, Australia
    Posts
    71

    Re: VB 6.0 Code for Back up and restore access database using DAO

    The easiest way I have found is to simply copy the database file...
    'Important...make sure the database workspace is closed!!!
    DBEngine.Workspaces(0).Close
    'copy the file
    FileCopy DatabaseNameAndAddress, NewDatabaseNameAndAddress

    You must also ensure that ALL recordsets opened by the app have been closed and set to nothing prior to closing the workspace.
    I usually have a sub procedure something like this
    Private Sub ReleaseAllRecordsets
    Rs1.Close
    Rs2.Close
    Set Rs1 = Nothing
    Set Rs2 = Nothing
    etc
    end sub
    Obviously, if you have recordsets that have been declared as private you will need to release those recordsets within the form that they were declared. Thats why I generally declare all recordsets as public.

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2009
    Location
    Manila, Phillippines
    Posts
    54

    Re: Back-up and restore using DAO,Acces as Database,vb6 application

    Thanks for your reply...FromDownUnder

    Actually here is my code,I use common dialog 6.0 to save it in any folder
    Code:
    Private Sub Command1_Click()
    Dim myDatabasePath As String
    Dim strFileName As String
    
    myDatabasePath = "D:\Information\Database.mdb" ' path of my original db file
    
    With CommonDialog1
        .Filter = "MS Access DB File | *.mdb"
        .ShowSave
        If Len(.FileName) > 0 Then
            strFileName = .FileName
        Else
            Exit Sub
        End If
    End With
    
    On Error GoTo Err
    Dim Conn As New DAO.DBEngine
    Dim strSource As String
    Dim strDest As String
    
    ' Ensure file is not read only
    SetAttr myDatabasePath, vbNormal
    strSource = "DataSource=" & myDatabasePath & ""
    strDest = "DataSource=" & strFileName & "dbengine(0)"
    
    Conn.CompactDatabase strSource, strDest
    
    Set Conn = Nothing
    
    Exit Sub
    Err:
    Debug.Print Err.Description
    End Sub
    =>this code is only backing up database, but when I play this code, it is running but no database saved in the folder,..Please help
    Last edited by si_the_geek; Nov 14th, 2009 at 05:34 AM. Reason: added code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width