Copying a file in Access v2

        0 votes: *****     3,86 views      No comments
by Allen Browne, 20 April 2005    (for Access v2)

Copy a file in Access 2

In the Declarations section of a module, incude (all on one line):

Declare Function abFileCopy Lib "MSAU200.DLL" Alias "#4" (ByVal  strSource As String, ByVal strTarget As String) As Long

And then the procedure:

Sub MyFileCopy (strSource As String, strTarget As String)
    'strSource is the source file name. strTarget is the target file name.
    'A disk and path may be included, but you cannot omit the name of the file.

    Dim lngResult As Long, strMsg As String
    lngResult = abFileCopy(strSource, strTarget)
    Select Case lngResult
    Case 0
        strMsg = "File copied"
    Case -101
        strMsg = strSource & " not available"
    Case -102
        strMsg = "Cannot open the destination. Did you specify the full name? Does a read-only file with that name exist?"
    Case -103
        strMsg = "Error reading " & strSource
    Case -104
        strMsg = "Error writing " & strTarget
    Case -105
        strMsg = "Insufficient memory"
    Case -106
        strMsg = "Invalid file name"
    Case Else
        strMsg = "An unknown error occured"
    End Select
    MsgBox strMsg
End Sub

Rate this article:  Your rating: PoorYour rating: Not so goodYour rating: AverageYour rating: GoodYour rating: Excellent

Have your say - comment on this article.

What did you think of 'Copying a file in Access v2'?

No comments yet.

Why not be the first to comment on this article?!

Have your say...

E-mail (e-mail address will be kept private)

Comments require approval before being displayed on this page (allow 24 hours).