Solved

Backup to and restore .mdb file

Posted on 2000-03-21
6
218 Views
Last Modified: 2010-05-18
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?
0
Comment
Question by:rdolivaw
6 Comments
 
LVL 9

Expert Comment

by:samopal
ID: 2641301
Before re-open your connection try to reassign .ConnectionString

HTH
0
 
LVL 1

Expert Comment

by:Argonaut
ID: 2642045
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
 
LVL 14

Expert Comment

by:wsh2
ID: 2642402
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rdolivaw
ID: 2644719
I'm accessing the Access database through an ODBC connection.  What's the correct way to reconnect?

Thanks for your hints, too, wsh2.

0
 
LVL 14

Accepted Solution

by:
wsh2 earned 50 total points
ID: 2645833
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
 

Author Comment

by:rdolivaw
ID: 2683596
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question