error 53 handler

mrxdm

New Member
Joined
Jan 2, 2018
Messages
20
1) I am unable to understand :confused: 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
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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
 
Upvote 0
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.
 
Upvote 0
I'd do it at the very beginning, before the error handler

the following is untested
Rich (BB 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


 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,986
Members
448,538
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top