Solved

Backup to and restore .mdb file

Posted on 2000-03-21
6
206 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
z = x + y – 1 6 56
DIR issue 7 47
Excel - Save a copy of work book 13 79
Access 2013 combo box not working 3 25
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now