Results 1 to 5 of 5
  1. #1
    justphilip2003 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ohio
    Posts
    125

    Intercepting error codes like 2220, file not found


    I have been attempting to intercept the screen message for a file not found following instruction { Me.ImgBox.Picture = GetPath() & "\Gallery_Pics\" & "CrNr963v1" & ".jpg"} and have my Event Procedure display a user friendly message to continue processing. My On error code directs processing to the error routine but the code "If Err.Number = 2220 Then ..." does not work and is skiped over to the "Else". Is it possible to intercept this error code? I will have many instances of executing this logic as the user pages through the multiple views to the not found condition. My logic works wonderfully when the records are found, thanks June7! TIA Phil

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Code:
    on error goto errhandler
    
    <your code here>
    
    errhandler
    if err.number = 2220 then 
       <do whatever you're going to do on this error>
    else
       <do whatever you want if the error is other than 2220>
    endif

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Don't know if it matters in your use, here, but Error 2220 is 'Access can't open the File, not 'cannot find the File.'

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I'd like to add one more thing. If you are using filesystemobject commands you can test the path of the file before you try to do anything with it and avoid error trapping altogether

    Code:
    dim fs 
    dim sTestFile as string
    
    set fs = createobject("scripting.filesystemobject")
    stestfile = = GetPath() & "\Gallery_Pics\" & "CrNr963v1" & ".jpg"
    if fs.fileexists(stestfile) then
    ' you may also use if fs.fileexists(stestfile) = True then
      <do what you're going to do if the file exists>
    else
      <do what you're going to do if the file does not exists>
    endif

  5. #5
    justphilip2003 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ohio
    Posts
    125
    Dumb me! in order to stop error screen displays, you must place the "On Error goto ..." statement before the code causing the error! Cheers and my thanks to all helping hands! Phil

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-02-2012, 09:54 PM
  2. Replies: 7
    Last Post: 06-08-2012, 09:55 PM
  3. Docmd.TransferText Spec File Not Found
    By Patrick.Grant01 in forum Programming
    Replies: 7
    Last Post: 05-22-2012, 09:32 AM
  4. "File Not Found" error
    By jgelpi16 in forum Programming
    Replies: 5
    Last Post: 04-21-2011, 10:17 AM
  5. codes for working days error
    By Harry in forum Programming
    Replies: 21
    Last Post: 10-15-2010, 02:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums