Search code examples
vbams-accessrenaming

File not found - error 53 when trying to rename file that exists


Very weird as this code was running last night!! I haven't changed anything and now it is failing as an error 53 - file not found.

Dim oldFilePath As String
Dim newFilePath As String
    FolderPath = "C:\Users\ME\Documents\Scans\"
    NewFileName = "Invoice " & InvID & " For " & LName & ", " & FName & ", " & ClaimNo
    oldFilePath = FolderPath & Filename
    newFilePath = FolderPath & NewFileName & ".pdf"
    Debug.Print oldFilePath
    Name oldFilePath As newFilePath  <--FAIL HERE

The debugs are coming out:

C:\Users\ME\Documents\Scans\ZephyrClaims20181018161309042577.pdf

Which is correct. This file exists and when I copy the debug code into a windows explorer address bar and press enter, then file opens in acrobat!

As mentioned this was working before. This is a function which cycles through specific files in a folder, renames them and then loops.

The list of files are filenames only in an access DB, and then you can see the folder path there, which does have the "\" on the end.

Totally stuck if anyone has an idea! I ahve also tried DIM as Variant, which had no effect. I find it just so weird that this has worked for about 20 files and now is failing.


Solution

  • The error was caused by the NEW file name having illegal characters in it as per user @Andre comment!!!