?
Solved

VB6 Copyfile function gives "Access is Denied" error

Posted on 2009-04-29
1
Medium Priority
?
546 Views
Last Modified: 2012-06-21
Hi Experts,

One of my users has struck a problem with my VB6 application.
This code works fine on dozens of sites.

On his PC:
     App.Path = "C:\Program Files\circly5"
     strDataPath = "C:\Program Files\circly5\data"

The error message is:

Copy failed. Access is denied.
"C:\Program Files\circly5\circ32.pif","C:\Program Files\circly5\data\circ32.pif"

Regards,
Leigh


RetVal = CopyFile(App.Path & "\circ32.pif", strDataPath & "\circ32.pif", False) 'Overwrite if file exists (20061116)
        If RetVal = 0 Then  ' failure
            
            '20051117: added code to output error message corresponding to Err.LastDllError
            Dim strErrorMessage As String
            strErrorMessage = ""
            If Err.LastDllError <> 0 Then
                strErrorMessage = strGetErrorMessage(Err.LastDllError)
            End If
        
            strMessage = "Copy failed. " & strErrorMessage & vbCrLf & chrCommandLineDelimiter & App.Path & "\circ32.pif" & chrCommandLineDelimiter & "," & chrCommandLineDelimiter & strDataPath & "\circ32.pif" & chrCommandLineDelimiter
            MsgBox strMessage, vbInformation
            Logger.Log 1, strMessage
         Else  ' success
            'PrintToDebugFile "Copy succeeded."
        End If

Open in new window

0
Comment
Question by:LeighWardle
1 Comment
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 1500 total points
ID: 24266956
That error usually has something to do with user privileges but it can also be caused by another application that might have the original file open. In this case you may have a handle open to the file and copyfile will fail if you don't have any shared permissions.
I am not sure what the number '20051117' means but the actual error number for Access Denied should be 5 if I can recall.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

755 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