Results 1 to 4 of 4

Thread: error 53 handler
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jan 2018
    Location
    Karachi, Pakistan
    Posts
    20
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question error 53 handler

    1) I am unable to understand what is the problem I am having in my bellow code, all is working well in this code but it is not showing an image picX.jpg instead of any image if it is not found (error number 53) in the work sheet "DnT".

    2) I need one more code line in bellow code that If folder name (imagesptp) of images not found then it shows a message box indicating the missing folder of images.



    code is here:
    Code:
    Private Sub ComboBox1_Click()
    Dim i As Long 'Integer
    Dim final As Integer
    
    
    On Error GoTo Handler:
    'On Error Resume Next
    
    
    For i = 3 To 2500
        If DnT.Cells(i, 19) = "" Then
        final = i - 1
        Exit For
        End If
    Next
    
    
    For i = 3 To final
    
    
        If ComboBox1 = DnT.Cells(i, 19) Then
    PUF7.Label1.Caption = "SN. " & DnT.Cells(i, 20)
    PUF7.Label2.Caption = "T. " & DnT.Cells(i, 17)
    PUF7.Label3.Caption = PUF7.Label22.Caption & DnT.Cells(i, 18)
    PUF7.Image1.Picture = LoadPicture(ThisWorkbook.Path & "\imagesptp\" & DnT.Cells(i, 15))
    PUF7.Label4.Caption = PUF7.Label23.Caption & DnT.Cells(i, 16)
    PUF7.Label5.Caption = DnT.Cells(i, 13)
    PUF7.Label12.Caption = DnT.Cells(i, 6)
    PUF7.Label13.Caption = PUF7.Label24.Caption & DnT.Cells(i, 5)
    
    
        Exit For
        End If
        Next
    
    
    Handler:
        If Err.Number = 53 Then
            Image1.Picture = LoadPicture(ThisWorkbook.Path & "\imagesptp\" & picX.jpg) 'LoadPicture("") 'E:\Tib e Sabir\imagesptp\picX.jpg
        End If
    
    
    End Sub

  2. #2
    Administrator starl's Avatar
    Join Date
    Aug 2002
    Location
    Everywhere!
    Posts
    5,859
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default Re: error 53 handler

    You can use the DIR function to check for the existence of a folder or specific file. Mix it with the LEN function and if the returned value is greater than 0, then the file or folder exists

    Len(Dir$(filePath, 16)) > 0 'check for existence of folder

    Len(Dir$(filePath)) > 0 'check for existence of file

  3. #3
    New Member
    Join Date
    Jan 2018
    Location
    Karachi, Pakistan
    Posts
    20
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: error 53 handler

    Thanks starl for a reply.
    Can you guide me more that where should I add your suggested line of code in my VBA codes? As you can see that the output results at my userform "PUF7" are dynamically changing as I click in combo box 1.

  4. #4
    Administrator starl's Avatar
    Join Date
    Aug 2002
    Location
    Everywhere!
    Posts
    5,859
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default Re: error 53 handler

    I'd do it at the very beginning, before the error handler

    the following is untested
    Code:
    If Len(Dir$(filePath, 16)) > 0 then 
        'folder exists; or if you're checking for the file, change the IF statement to the other
        'do nothing
    else 
        'folder doesn't exist 
        'have some code to handle it the way you want. For example, a message box, then Exit the sub
        'Exit Sub (or goto errhandler)
    end if
    
    'rest of your code
    



Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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