Copying a file in Access v2

        Not Rated      3,072 views      0 comments
by Allen Browne, 20 April 2005    (Access 2)

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: Poor Your rating: Not so good Your rating: Average Your rating: Good Your 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...

Name
E-mail (e-mail address will be kept private)
Comments
Verify Code
Verification Code


It may take 30 seconds after clicking submit - please be patient to avoid duplicate submissions.  

All comments must be approved before being displayed on this web page.  This process may take up to 24 hours.