Solved

access vba run-time error '70' permission

Posted on 2010-11-11
6
1,060 Views
Last Modified: 2012-05-10
I am getting the error "run-time error '70' permission denied" when performing
FileCopy file1, file2
This is due to the fact that file1, which is an Access database, is open.

Is there a way around this? This code is run overnight and obviously some users are leaving the db running. This is not something I can do much about so need to find a work-around.

Any ideas?
0
Comment
Question by:rick_danger
[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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34111112
try this, place the whole code in a regular module



pass the path and name of currentdb and new path and db name
could be on the same path/folder but must be different db name, say add a datetime to the backup copy
Option Compare Database
Option Explicit

Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long

Public Function fnc_CopyFile(ByVal strCurrentDB As String, ByVal strBackUpCopy As String) As Boolean

    Dim ret As Long

    On Error Resume Next
   
    DoCmd.Hourglass True
    ret = CopyFile(strCurrentDB, strBackUpCopy, True)
    If ret = 0 Then
        MsgBox "File Copy failed.", vbCritical, "File Copy"
        fnc_CopyFile = False
    Else
        fnc_CopyFile = True
    End If
    DoCmd.Hourglass False
End Function

Open in new window

0
 

Author Comment

by:rick_danger
ID: 34111368
Thanks capricorn1
I think that will only tell me if it failed. I need to find a way to make it work, even if the database is open. I need to somehow find a way of copying a database file that is already open.
 
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34111419
that code is suppose to copy the open database, so, try it first.
of course if there is an error when copying the file, it will tell you that the copy process failed.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:rick_danger
ID: 34111654
I don't quite understand where to put and how to run this code. This is part of my code:
Public Sub DoRebuild()
    ' First off ... copy "R:\Stephen hill time ..." to Local C: Drive
   
    strSource = "R:\Databases\time and Expenses Database.mdb"
    FileCopy strSource, "R:\Databases\TimeExpensesBackup.mdb"
    FileCopy strSource, "C:\Databases\time and Expenses Database.mdb"
    ' then - copy the table "InvoiceSummary" - (within the 'un-copied' file)
    ' (so as to retain Notes and Invoice Preparer data)
    ' On the fly, get and use the copy as a look-up
    ' Finally, at the end, delete the copy (so as it can be copied again)
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 34117197
Where did you get the code from?
The author of that code should provide you with instructions.

Most Experts here don't like to comment on code that they did not create, because it is not known if the code is even valid for what you need to do.

Beside, there is no way to "Work around" the error or "make it work".
The fact of the matter is that you cannot (easily) copy a database file that is Open and/or In use.

Furthermore if you try to close the DB file that is in use, corruption may result.

You need to make sure the file is closed before trying to access it.
So your first step would be to figure out why the file is being help open.

You can also "BackUp" the DB by creating code that copies all of the Objects to another DB.
(But this will involve more complex code)

Or investigate this group of products:

This will perform almost any basic database maintenance task:
http://www.fmsinc.com/MicrosoftAccess/Scheduler.html

This will monitor who in in the DB and give you options for kicking them out.
http://www.fmsinc.com/MicrosoftAccess/monitor.asp 

JeffCoachman


0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 34117331
if you use the File System object, you will not have this issue.  it will allow you to copy an open Access database,

mx
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

617 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