I'm really struggling with this one! I have a userform which amongst other things contains two Image Placeholders; Image1 and Image2. When I click on an item in the ListBox1 this should then change the images of both placeholders based on what item they have clicked on in the listbox. The code I have placed below works for Image1 but no Image 2 even though it's the same code! For context, the listbox populates other textboxes on the userform. I have defined a range on the sheet as 'myName' which is used for Image1. I have defined another range as 'vicName' which is for Image2. When I click on an item in the listbox the code will then take the value of the listbox and then search for the matching name in a folder found in the workbook path. I'm just very confused as to why this works for one image but not the other! Any suggestions would be greatly appreciated!
EmpFound works, but vicFound doesn't. It won't even load the 'nopic.gif'!Private Sub listBox1_Click() Dim EmpFound As Range Dim vicFound As Range Dim fPath As String Dim vfPath As String With Range("myName") Set EmpFound = .Find(ListBox1.Value) On Error Resume Next If EmpFound Is Nothing Then Image1.Picture = LoadPicture(fPath & "nopic.gif") Else With EmpFound 'Look in the directory where this workbook is located. fPath = ThisWorkbook.Path & "\Pictures\" On Error Resume Next 'If a matching picture is found then display it. Image1.Picture = LoadPicture(fPath & "\" & ListBox1.Value & ".jpg") 'If No picture found then display the default picture. If Err = 0 Then Exit Sub Image1.Picture = LoadPicture(fPath & "nopic.gif") With Range("vicName") Set vicFound = .Find(VictimDetailsMain.tbName.Value) On Error Resume Next If vicFound Is Nothing Then Image2.Picture = LoadPicture(vfPath & "nopic.gif") Else With vicFound vfPath = ThisWorkbook.Path & "\Pictures\Victims" On Error Resume Next Image2.Picture = LoadPicture(vfPath & "\" & VictimDetailsMain.tbName.Value & ".jpg") If Err = 0 Then Exit Sub Image2.Picture = LoadPicture(vfPath & "nopic.gif") Set EmpFound = Nothing Set vicFound = Nothing End With End If End With End With End If End With End Sub
Any Thoughts?
Bookmarks