FileCopy - Access Denied

R

Rose B

I have utilised some coding that I got from this forum to manage MDE
versions. On most PCs it works fine, but on a couple of users I get Access
Denied error when trying to do the FileCopy. The code that I use is below.
Any ideas? (There is no issue doing the copy manually using copy/paste)

If ServerVersion > LocalVersion Then
DoCmd.OpenForm "UpdateNotice"
Kill LocalFile
FileCopy ServerFile, LocalFile
DoCmd.Close acForm, "UpdateNotice"
End If
 
S

Stefan Hoffmann

hi Rose,

Rose said:
On most PCs it works fine, but on a couple of users I get Access
Denied error when trying to do the FileCopy. The code that I use is below.
Any ideas? (There is no issue doing the copy manually using copy/paste)
Kill LocalFile
FileCopy ServerFile, LocalFile
The problem may arise due to the NTFS rights your users have.

For example, an ordinary user has no write/delete rights on C:\ or
C:\Program Files.


mfG
--> stefan <--
 
R

Rose B

Hi Stefan,

the destination file is to be copied into My Documents/My Apps, which I
would have thought OK - if it were NTFS issues would the users be unable to
copy/paste manually to? (They can do this OK). I have also tried to change
the destination folder to a different one to which only the user has access,
and still the same issue.
 
S

Stefan Hoffmann

hi Rose,

Rose said:
the destination file is to be copied into My Documents/My Apps, which I
would have thought OK - if it were NTFS issues would the users be unable to
copy/paste manually to? (They can do this OK). I have also tried to change
the destination folder to a different one to which only the user has access,
and still the same issue.
Another issue may be, that your file is still open and cannot be killed
or overwritten. So use a more sophisticated error handler:

On Local Error GoTo LocalError

If ServerVersion > LocalVersion Then
10 DoCmd.OpenForm "UpdateNotice"
20 Kill LocalFile
30 FileCopy ServerFile, LocalFile
40 DoCmd.Close acForm, "UpdateNotice"
End If

Exit Sub

LocalError:
MsgBox "Error in line " & Erl() & vbCrLf & Err.Description


mfG
--> stefan <--
 
R

Rose B

OK - I will give that a go when I am in the office next (just left there). I
am somehow doubtful though as when after the routine has failed the original
file has indeed been deleted. I put in a MsgBox line to see exactly where the
error was happening, and with what error and found that the "Kill" command
executed OK, but an Access Denied error occurred at the FileCopy statement.

I did wonder whether I needed to put in some kind of delay for some reason???
 
D

dymondjack

As Stefan has mentioned, I think it might take the system a little bit longer
to process the file deletion than it takes your code to the next line. So,
probably what is happening is the filecopy statement is seeing that there is
still a file there, with a system process running on it (the deletion). This
will generally result in this type of error.

You can use the Sleep API to wait for a specified period of time. Throw
this in the declarations portion of a standard module:

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

and call it from your function by using a line like this:

Sleep 1000

(1000 will sleep your code for one second).


--
Jack Leach
www.tristatemachine.com

- "A designer knows he has reached perfection not when there is nothing left
to add, but when there is nothing left to take away." - Antoine De Saint
Exupery
 
R

Rose B

Thanks - I will do this, although will be end next week now before I can get
back to the users....I will update the item to assume that it works -
thanks!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top