By pass Error Message '53' File not found
I wrote a Module in access that will analized a particular column in a table in my case is "Part No" and then it searches for the image matching the part number and copies it and pastes it in a designated folder. The problem I'm facing is that if there is not a picture the function will give me an error '53' file not found and then exits the code. I found some info about error handling but no luck. Any help will be appreciated. Thank you in advance.
Here is my CODE.
Code:
Option Compare Database
Option Explicit
Function CCSImageLookup()
Dim rst As Recordset
Dim fs As Object
Dim oldPath As String, newPath As String
Set rst = CurrentDb.OpenRecordset("SELECT trim(CCS_PartsLookUp.[Part No]) as [Part No]" _
& " FROM CCS_PartsLookUp")
While Not rst.EOF
oldPath = "T:" 'Folder file is located in
newPath = "C:\Users\Desktop\Pictures" 'Folder to copy file to
Set fs = CreateObject("Scripting.FileSystemObject")
'MsgBox rst![Part No] & ".jpg"
fs.CopyFile oldPath & "\" & rst![Part No] & ".jpg", newPath & "\" & rst![Part No] & ".jpg" '<---- this is the line where the error happens if it does not find
Set fs = Nothing '--matching Part No.
rst.MoveNext
Wend
End Function