Consulting

Results 1 to 3 of 3

Thread: By pass Error Message '53' File not found

  1. #1

    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.



    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
    Last edited by Bob Phillips; 06-06-2014 at 08:51 AM. Reason: Added VBA tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,446
    Location
    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
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3

    Thumbs up Thank you

    Thank you very much for your help, It work perfectly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •