FileCopy problem

here4real

Registered User.
Local time
Today, 16:12
Joined
May 1, 2013
Messages
87
I have VBA code (Access 2007) that first copies a file using UNC convention and later uses a MergePDF procedure to consolidate that initial copied file with the generated PDFs... On my PC, Windows 7 Professional 32-bit, it works fine... On other people's PCs, the FileCopy does not generate any error but the file is never copied so that when it tries to do the merge later I get an error 53 that the file isn't there... I know this is happening on a Windows XP PC and a 64-bit Windows 7 PC... Both PCs can browse to the source location of that file to be copied, i.e. the UNC is accessible...

Why would this be happening and how can I fix it???
 
Can you copy the file manually on the two computers, (it could be some permission issues)?
 
I can manually copy from source location to destination... When it does the copy, I see on the screen the copy taking place... But after it supposedly finishes, the file isn't there...
 
Sounds to me like there might be the problem between 32-bit and 64-bit versions.. Check the References that the Code uses.. And see if the DLL's are available in the SysWOW64 Folder.. What is the Exact error you are getting?
 
One of the PC's having the problem is running XP... I tried using the shell command and I actually see the copy taking place but the file doesn't show up and there is no error message... VERY strange...
 
Is it possible to see the code you are using? When you say XP, I recall a problem accessing the User Profile Path is different in XP and other OS of Windows..
 
Here is the meaningful snippet:

Dim ETCPOrig As String
Dim ETCPDest As String

Set db = CurrentDb()

If Not IsDate(DateEnterB) Or Not IsDate(DateEnterE) Then
MsgBox ("You must enter a valid date!!!")
Else
NPDateB = DateValue(DateEnterB)
NPDateE = DateValue(DateEnterE)

DoCmd.SetWarnings False

' Copy ET Cover Page

ETCPDest = Environ("temp") & "\" & Format(Date, "mm-dd-yy") & " - ET Report.pdf"
ETCPOrig = "\\fs1\statsmfhc\MIS\Harry Access DBs\ET Cover Page.pdf"

'FileCopy ETCPOrig, ETCPDest

bSuccess = ShellFileCopy(ETCPOrig, ETCPDest, True)


As you can see I commented out the FileCopy as that wasn't working... It works perfectly on my PC (Windows 7 Pro 32-bit)...


Here is the shellcopy code which I gleaned from another site:



Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String
End Type

Private Declare Function SHFileOperation Lib "shell32.dll" _
Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_NOCONFIRMATION = &H10
Private Const FO_COPY = &H2




Public Function ShellFileCopy(src As String, dest As String, _
Optional NoConfirm As Boolean = False) As Boolean

'PURPOSE: COPY FILES VIA SHELL API
'THIS DISPLAYS THE COPY PROGRESS DIALOG BOX
'PARAMETERS: src: Source File (FullPath)
'dest: Destination File (FullPath)
'NoConfirm (Optional): If set to
'true, no confirmation box
'is displayed when overwriting
'existing files, and no
'copy progress dialog box is
'displayed

'Returns (True if Successful, false otherwise)

'EXAMPLE:
'dim bSuccess as boolean
'bSuccess = ShellFileCopy ("C:\MyFile.txt", "D:\MyFile.txt")

Dim WinType_SFO As SHFILEOPSTRUCT
Dim lRet As Long
Dim lflags As Long

lflags = FOF_ALLOWUNDO
If NoConfirm Then lflags = lflags & FOF_NOCONFIRMATION
With WinType_SFO
.wFunc = FO_COPY
.pFrom = src
.pTo = dest
.fFlags = lflags
End With

lRet = SHFileOperation(WinType_SFO)
ShellFileCopy = (lRet = 0)

End Function
 
Here is the meaningful snippet:

Code:
Dim ETCPOrig As String
    Dim ETCPDest As String

    Set db = CurrentDb()

    If Not IsDate(DateEnterB) Or Not IsDate(DateEnterE) Then
        MsgBox ("You must enter a valid date!!!")
    Else
        NPDateB = DateValue(DateEnterB)
        NPDateE = DateValue(DateEnterE)
        
        DoCmd.SetWarnings False
        
        ' Copy ET Cover Page
        
        ETCPDest = Environ("temp") & "\" & Format(Date, "mm-dd-yy") & " - ET Report.pdf"
        ETCPOrig = "\\fs1\statsmfhc\MIS\Harry Access DBs\ET Cover Page.pdf"
        
        'FileCopy ETCPOrig, ETCPDest
        
        bSuccess = ShellFileCopy(ETCPOrig, ETCPDest, True)

As you can see I commented out the FileCopy as that wasn't working... It works perfectly on my PC (Windows 7 Pro 32-bit)...


Here is the shellcopy code which I gleaned from another site:


Code:
Private Type SHFILEOPSTRUCT
        hwnd As Long
        wFunc As Long
        pFrom As String
        pTo As String
        fFlags As Integer
        fAnyOperationsAborted As Long
        hNameMappings As Long
        lpszProgressTitle As String
End Type

Private Declare Function SHFileOperation Lib "shell32.dll" _
Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_NOCONFIRMATION = &H10
Private Const FO_COPY = &H2




Public Function ShellFileCopy(src As String, dest As String, _
    Optional NoConfirm As Boolean = False) As Boolean

'PURPOSE: COPY FILES VIA SHELL API
'THIS DISPLAYS THE COPY PROGRESS DIALOG BOX
'PARAMETERS: src: Source File (FullPath)
            'dest: Destination File (FullPath)
            'NoConfirm (Optional): If set to
            'true, no confirmation box
            'is displayed when overwriting
            'existing files, and no
            'copy progress dialog box is
            'displayed
            
            'Returns (True if Successful, false otherwise)
            
'EXAMPLE:
  'dim bSuccess as boolean
  'bSuccess = ShellFileCopy ("C:\MyFile.txt", "D:\MyFile.txt")

Dim WinType_SFO As SHFILEOPSTRUCT
Dim lRet As Long
Dim lflags As Long

lflags = FOF_ALLOWUNDO
If NoConfirm Then lflags = lflags & FOF_NOCONFIRMATION
With WinType_SFO
    .wFunc = FO_COPY
    .pFrom = src
    .pTo = dest
    .fFlags = lflags
End With

lRet = SHFileOperation(WinType_SFO)
ShellFileCopy = (lRet = 0)

End Function
 
On the XP system what is the output you get when you use..
Code:
? Environ("temp")
 

Users who are viewing this thread

Back
Top Bottom