Log in

View Full Version : By pass Error Message '53' File not found



junior6202
06-06-2014, 07:13 AM
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.




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

Bob Phillips
06-06-2014, 08:55 AM
Maybe


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")

Set fs = CreateObject("Scripting.FileSystemObject")
While Not rst.EOF
oldPath = "T:" 'Folder file is located in
newPath = "C:\Users\Desktop\Pictures" 'Folder to copy file to
'MsgBox rst![Part No] & ".jpg"
If Dir(oldPath & "\" & rst![Part No] & ".jpg") <> "" Then fs.CopyFile oldPath & "\" & rst![Part No] & ".jpg", newPath & "\" & rst![Part No] & ".jpg"
rst.MoveNext
Wend
Set fs = Nothing '--matching Part No.

End Function

junior6202
06-06-2014, 11:46 AM
Thank you very much for your help, It work perfectly.