Applecore Pages on Microsoft Access

Controlling external files from within Access

VBA has some built-in ways of deleting, renaming, moving or copying files, but these are not always obvious.

Copying a File
The VBA function for copying a file is FileCopy. Note that the file cannot be open for you to copy the file.
Renaming a File
The VBA function to rename a file is Name.
Moving a File
The VBA function to move a file is the same as that to rename it, i.e. Name.
Deleting a File
The VBA function for deleting a file is Kill. Note that this will completely bypass the Recycle Bin. If you wish to delete a file to the Recycle Bin, the you will need to use an API call, as described here.
Checking for the existence of a File
Another thing that you might wish to do when handling files is to check if it exists, for example before deleting it. The best way of doing this is to use the Len and Dir functions together:

If Len(Dir(strFile))>0 Then
'   We know that the file exists.
Else
'   The file doesn't exist.
End If

This method is quicker than checking if Dir(strFile)="" as Access internally stores the length of a string as well as the value.

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 13:58:06