Move folder

constantG

Registered User.
Local time
Today, 12:29
Joined
Jun 24, 2009
Messages
92
Can anyone see a problem with the following code?

Code:
Function MoveFolder(sFolderSource As String, sFolderDestination As String, _
                    bOverWriteFiles As Boolean) As Boolean
On Error GoTo Error_Handler
    Dim fs As Object
 
    MoveFolder = False
    Set fs = CreateObject("Scripting.FileSystemObject")
    fs.CopyFolder sFolderSource, sFolderDestination, bOverWriteFiles
    fs.DeleteFolder sFolderSource, True
    MoveFolder = True
 
Error_Handler_Exit:
    On Error Resume Next
    Set fs = Nothing
    Exit Function
 
Error_Handler:
    If Err.Number = 76 Then
        MsgBox "The 'Source Folder' could not be found to make a copy of.", _
                vbCritical, "Unable to Find the Specified Folder"
    Else
        MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
               "Error Number: " & Err.Number & vbCrLf & _
               "Error Source: MoveFolder" & vbCrLf & _
               "Error Description: " & Err.Description, _
               vbCritical, "An Error has Occured!"
    End If
    Resume Error_Handler_Exit
End Function

Where sFolderSource = "C:\Familygrams_Received\SHIPNAME\Signal" which exists and
sFolderDestination = CurrentProject.path & "\SHIPNAME\Signal\Archive\" which does not yet exist.

The error handler kicks in at fsCopyFolder line with Error 76
 
have you looked at FS.COPYFOLDER in vba help? maybe you're violating a rule that is in that help file. that would be my guess.

as an alternative to this too, you could simply shell COMSYS and run 2 dos commands for this. XCOPY and DELTREE. or XCOPY and DEL (with a switch)
 
Cheers I'll check out your first idea. The second one is interesting but I am sure that before I started playing around with my database and in the annuls of changes that I have made to it, it was working at one point.

Must be doing something wrong.
 
Hi

Have you checked the value of your varriable "bOverWriteFiles". The help files tell us this:
If destination is a directory, an attempt is made to copy the folder and all its contents. If a file contained in source already exists in destination, an error occurs if overwrite is False. Otherwise, it will attempt to copy the file over the existing file.

If bOverWriteFiles=false an error would be expected.
 
Thanks to all, as usual expert advice. The source path was made up from values in a table and I had missed a "\" in making up the path.

Look and ye shall find!!!!!!!!
 

Users who are viewing this thread

Back
Top Bottom