Runtime Error 53 file not found

valasso

New Member
Joined
Jun 15, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hi All
I am new to forum and a noob with vba / macros i have checked other posts regarding this error but it has not helped. So if i post my code can someone please lead me in the right direction please.

Background
I have a worksheet with forms and on the forms i have a multilevel combo-boxes. When you select Combo1 you then get a selection that you can choose from in Combo2 once you select a item it should fill in the image bozx with the item you selected and this works as you continue to fill out the form all is fine and at the end when you click the submit button it writes the info to another sheet in the workbook which it does but it then gives me the error Runtime Error 53 - File not Found. Very frustrating as i do not understand why.

Code add_frm
Private Sub ComboBox1_Change()

Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DropDown")

Dim i As Integer

Me.ComboBox2.Clear

For i = 2 To sh.Range("A" & Application.Rows.Count).End(xlUp).Row
If sh.Range("A" & i).Value = "Cabinet Name" Then
If sh.Range("C" & i).Value = Me.ComboBox1.Value Then
Me.ComboBox2.AddItem sh.Range("B" & i).Value


End If


End If


Next i

End Sub

Private Sub ComboBox2_Change()
Image1.Picture = LoadPicture("C:\Anertex" & "\" & ComboBox2.Value & ".jpg")
'Image1.Picture = LoadPicture(ThisWorkbook.Path & "\" & ComboBox2.Value & ".jpg")' - -- i have aslo tried this
End Sub


All the files exists in the correct path and while in the form it does show you the correct jpg.. Thanks
 

Some videos you may like

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

QuietRiot

Well-known Member
Joined
May 18, 2007
Messages
1,077
Do you get an error at all when this line is commented out? Image1.Picture = LoadPicture("C:\Anertex" & "\" & ComboBox2.Value & ".jpg")

Thinking maybe your ComboBox2.value is null at a certain point and it might be throwing the error?
 

valasso

New Member
Joined
Jun 15, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Thanks for your reply
Yes when that line is commented out it all works but i do not understand why this 1 line throws up this error.
 

QuietRiot

Well-known Member
Joined
May 18, 2007
Messages
1,077
You could add a file check like below, but I believe it's something to do with combobox2 being null after it runs.

VBA Code:
Private Sub ComboBox2_Change()
    Dim FullFilePath As String
    
    FullFilePath = "C:\Anertex" & "\" & UserForm1.ComboBox2.Value & ".jpg"
    
    If Dir(FullFilePath) <> "" Then
        Image1.Picture = LoadPicture(FullFilePath)
    End If
    
End Sub
 

valasso

New Member
Joined
Jun 15, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Thanks for your reply QR I will add this code and see how it goes. I believe your correct in regards to the combo2 maybe be null. When thinking of the what happens when the code is run, my thought is with the UserForm and the multilevel combobox it places the correct text in the box and it does show the correct picture you press the submit button and it does write the info into the worksheet DATA and at the end of the code if i am correct it clears the UserForm and this is when it must see the null value in the combo2 and then throw the error at the end. What do think would you have any thoghts on how to finish that action of submit so it does not look at the combo2 and throw the error. I may have not worded this correctly so please excuse me.
 

valasso

New Member
Joined
Jun 15, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hi QR
Sorry for the delayed response. I have tried the code you have suggested but it now doesn't show the image. I have tried a few different ways but no go. May i ask do you know a better way of trying to display a image in a userform using a mutlilevel combobox. Any suggestion is greatly appreciated.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,306
Messages
5,571,460
Members
412,394
Latest member
divster27
Top