Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Backup to and restore .mdb file

Posted on 2000-03-21
6
Medium Priority
?
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 150 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

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!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

618 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