Name function in Access 2002 (XP)

  • Thread starter Thread starter pvp
  • Start date Start date
P

pvp

Guys, I am doing a complicated series of renames of files
from Access VBA. I need to know how such a (re)name
operation can fail so that I know whether to try and
catch such failures. Has it ever failed to anyone's
knowledge?

Many thanks.
 
pvp said:
Guys, I am doing a complicated series of renames of files
from Access VBA. I need to know how such a (re)name
operation can fail so that I know whether to try and
catch such failures. Has it ever failed to anyone's
knowledge?


I don't all of the things that might happen, but the common
problems are that the file you want to rename doesn't exist
or the new name is already assigned to an existing file. I
would check these situations before trying to rename. But
for everything else (no permission, in use, etc), use error
handling and add cases as you trip over problems:

Name stroldname As strnewname
ExitSub:
Exit Sub

ErrHandler:
Select Case Err.Number
Case ??
? ? ?
Case Else
MsgBox Err.Number & " - " & Err.Description
End Select
Resume ExitSub
End Sub
 
There are *myriads* of reasons that a rename can fail, e.g.:
- the old file name does not exist;
- the path is invalid;
- the network connection is not available;
- the drive is empty;
- the disk is corrupted (chkdsk error);
- the new file name is invalid (bad characters, too long, ...);
- the new name includes a path that does not yet exist);
- the media is not writable (CD-ROM);
- the disk is write protected;
- you do not have write permission to the drive/file/folder;
- the file is currently in use;
- your software is being run on a future file system, and an error occured
that you never imagined;
- many others.

The VBA errors are very specific when there is a problem. The only sensible
approach is to use error handling, and let VBA report what particular error
occurred if there was a problem.
 
Sir, you have a gift fro being encouraging ! (8v})>

Thankfully most of those cannot apply to my situation.
Anyway now I know that I'd better notassume that rename
will work.
Rats!
Thanks.
 
Back
Top