Solved

Permission Denied error 70 when using filecopy

Posted on 2011-03-19
6
1,177 Views
Last Modified: 2012-05-11
I have a split database and wish to make a copy of the data back-end via code.  To do this, I have a button on a form which calls the copy routine.  One of the first actions in the code is to close the form which called the routine to ensure any remaining unwritten data is written to the database.

When I step through the code using F8 the routine works perfectly.  When I run the code from the button on the form, I get an Error 70 Permission Denied error on the FileCopy line.  I suspect that the backend database is still locked.  but I don't know how I can get around this problem.

I've tried putting in a loop that continues to try the filecopy routine until the Error 70 doesn't occur.  However, this doesn't seem to work as the routine gets trapped in the loop.

Is there a way to test if the Error 70 will occur before attempting it?  Maybe testing to see if the back-end database is still locked?

Here's the code:
=============
Sub CreateBackUp()
    On Error GoTo ErrTrap
   
    'close any open forms and present the backup dialog
    DoCmd.Close acForm, "frmContacts"
   
    'grab the current backend name to rename the copy when its made
    Dim myLinkedName
    myLinkedName = CurrentDb.TableDefs("tblContacts").Connect
    myLinkedName = Right(myLinkedName, Len(myLinkedName) - InStr(1, myLinkedName, "="))
   
    'make the copy
    FileCopy Source:=myLinkedName, destination:=Left(myLinkedName, Len(myLinkedName) - 6) & " " & Format(Now(), "yyyymmddhhss") & ".dcsdb"
   
    'reopen the contacts form
    DoCmd.OpenForm "frmContacts"
   
    'avoid the error trap
    Exit Sub
     
ErrTrap:
    MsgBox "An unexpected error occured and is described as: " & Err.Description
    DoCmd.OpenForm "frmContacts"
    Exit Sub
   
End Sub
=================

Many thanks for your help.
0
Comment
Question by:BigDaveStafford
  • 4
  • 2
6 Comments
 
LVL 75
ID: 35174248
Instead of using FileCopy, use the File System Object, wherein you can copy an open file.

Here are some links to get you started:

http://msdn.microsoft.com/en-us/library/aa242124%28VS.60%29.aspx

http://msdn.microsoft.com/en-us/library/hww8txat%28VS.85%29.aspx

http://msdn.microsoft.com/en-us/library/z9ty6h50.aspx

mx
0
 

Author Comment

by:BigDaveStafford
ID: 35174321
Thanks for this comment.  If I use the File System Object can I be sure that any data from the form has been written to the backend file?

Thanks
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 250 total points
ID: 35174334
" If I use the File System Object can I be sure that any data from the form has been written to the backend file?"

The FSO in itself will not insure that. You must do that, by Saving any current data that is being edited. But that should be easy to do.

I use the FSO daily in a backup routine that backups up 25 mdb backends on a server.  

Where exactly are you running this backup code from ?
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:BigDaveStafford
ID: 35175077
Thanks again. I'll give the fso a try. I'm running the code from the front end of a split database so ensuring there's no pending edits should be easy.

Thanks
0
 
LVL 75
ID: 35175869
ok
0
 
LVL 75
ID: 35176290
LOTS of cool things you can do with FSO ... pretty easy to use also.

thx.mx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

947 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

24 Experts available now in Live!

Get 1:1 Help Now