Backup to and restore .mdb file

I'm trying to set up a couple buttons for the user to backup and restore an Access database file.  The backup part works ok, but when I restore I have difficulty.  The code so far is as follows:

Private Sub cmdGo_Click()
    Dim fso
   
    On Error GoTo errDiskError
   
    envMedical.cnnExams.Close  'Close connection

    Set fso = CreateObject("Scripting.FileSystemObject")
    Screen.MousePointer = vbHourglass
   
    Do While Not fso.FileExists("A:\MedAccess.mdb")
        If MsgBox("Wrong diskette; please fix and try again", _
                     vbOKCancel + vbExclamation, _
                    "Wrong disk") = vbCancel Then
                        Unload Me
                        Exit Sub
       
        End If
    Loop

    DoEvents
   
    Kill "C:\MedAccess\MedAccess.mdb"
    FileCopy "A:\MedAccess.mdb", "C:\MedAccess\MedAccess.mdb"

    envMedical.cnnExams.Open  'Open connection
    envMedical.rsdcdExams.Open  'Open table
    envMedical.rsdcdPSErr.Open  'Open table

    Screen.MousePointer = vbNormal
   
    MsgBox "Restore successful", vbOKOnly, "Restore complete"
    Exit Sub
   
errDiskError:
    MsgBox "Error " & Err.Number & vbCr & Err.Description, _
        vbOKOnly + vbExclamation, "Disk Error"
    Resume Next

End Sub


The actual restore from the stiffy seems to go OK, based upon file modification times, but when opening the tables I get "Error number 3709 The application requested an operation on an object with a reference to a closed or invalid Connection object." from my error handler.

What am I missing?
rdolivawAsked:
Who is Participating?
 
wsh2Connect With a Mentor Commented:
And.. I'm now thinking.. your problem is perhaps not the connection.. but rather.. TIMING. Try adding a Do Events and a Timer / Delay after the FileCopy and see if that works. Also, right after the second open, you may want to check the errors collection for any messages.. <smile>
0
 
samopalCommented:
Before re-open your connection try to reassign .ConnectionString

HTH
0
 
ArgonautCommented:
Your connection is destroyed when the original database is deleted.  You must re-rstablish your connection and re-initialize your object variables with the Set command.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
wsh2Commented:
Argonaut:
Please try the comment button.. <wink>.

-------------------------------------
You implement this statement early in the Sub Routine.

envMedical.cnnExams.Close  'Close connection

Have you also closed any Open Recordsets? Do so if you haven't already.

--------------------------------------

What is with the Unload Me in your File Exists test? As you have active references to Me.. its not going to work.

Do While Not fso.FileExists("A:\MedAccess.mdb")
        If MsgBox("Wrong diskette; please fix and try again", _
                     vbOKCancel + vbExclamation, _
                    "Wrong disk") = vbCancel Then
                        Unload Me
                        Exit Sub
         
        End If

-------------------------------------
You should add an Existence test or an On Error before this statement..

Kill "C:\MedAccess\MedAccess.mdb"

-------------------------------------
The proper syntax for this statement shoud be

fso.FileCopy "A:\MedAccess.mdb", "C:\MedAccess\MedAccess.mdb"

-------------------------------------
0
 
rdolivawAuthor Commented:
I'm accessing the Access database through an ODBC connection.  What's the correct way to reconnect?

Thanks for your hints, too, wsh2.

0
 
rdolivawAuthor Commented:
Still haven't really resolved the issue but it's a minor thing at this point as there's still a lot of other areas to complete on the app.  Thanks for your advice; I've filed it and will readdress it in the future when I get back around to this.  May be back in touch then.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.