Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileCopy gives "Permission Denied" error

Status
Not open for further replies.

maggielea

Programmer
Jun 19, 2007
6
US
The following code gives me "Permission Denied" error at the FileCopy statement. Any idea what I'm doing wrong? Any help is appreciated! Maggie

Function gfbackupdatabase() As Boolean

On Error GoTo Err_Backup

'Use this to create a copy of the blank original database
Dim Sourcefile, Destinationfile
Sourcefile = "C:\Documents and Settings\user\My documents\gandee\Gandee071707_BE.mdb"
Destinationfile = "C:\Documents and Settings\user\My documents\gandee\COPY1_BE.mdb"

FileCopy Sourcefile, Destinationfile

Exit_Backup:

Exit Function

Err_Backup:
MsgBox Error$
Resume Exit_Backup

End Function
 
Help said:
If you try to use the FileCopy statement on a currently open file, an error occurs.

Are you executing this for your currently open mdb?
The FileCopy method of the Scripting FileSystemObject object shall do the work.

Code:
Function gfbackupdatabase() As Boolean

On Error GoTo Err_Backup

'Use this to create a copy of the blank original database
Dim Sourcefile As String, Destinationfile As String
Sourcefile = "C:\Documents and Settings\user\My documents\gandee\Gandee071707_BE.mdb"
Destinationfile = "C:\Documents and Settings\user\My documents\gandee\COPY1_BE.mdb"

With CreateObject("Scripting.FileSystemObject")
    .copyfile Sourcefile , Destinationfile ', True 
End With
gfbackupdatabase = True

Exit_Backup:
    Exit Function

Err_Backup:
    gfbackupdatabase = False
    MsgBox Error$
    Resume Exit_Backup

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top