Advice for showing image after ListBox entry selected

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Evening,
Ive nearly completed this but need some help please with regards showing an image after the item has been selected from the ListBox

I have TextBox1 & ListBox1
There is also the ImageBox

I have Table6 which is the stored items that get loaded into the ListBox.
I start to type in the TextBox & the ListBox entries start to narrow down depending on what i type in the TextBox.
Now this is where im stuck.
I would like to select an item from the ListBox & have its photo shown in the ImageBox

Lets say at present the ListBox entries total 22
The photos in question are only say 6

Reason being a different entry = the same Image.
Example of path for image C:\Users\Ian\Desktop\REMOTES ETC\BIKE STUFF\HONDA1.jpg


This is the code i have in use which works.

Rich (BB code):
Option Explicit

Private myList() As Variant
Private Sub ListBox1_Click()
    
       HondaParts.MyPartNumber.Text = ListBox1.Text
          Unload PNForm
       HondaParts.Show
End Sub

Private Sub TextBox1_Change()
       TextBox1 = UCase(TextBox1)
    Static NoMatch As Boolean
    
    If Len(TextBox1) > 0 Or NoMatch Then
        NoMatch = False
        ListBox1.Visible = True
        ListBox1.List = GetCutList()
        If IsEmpty(ListBox1.List(0)) Then
            MsgBox "NO SUCH NUMBER FOUND", vbCritical, "HONDA EPC NUMBER CHECK"
            ListBox1.List = myList
            NoMatch = True
            TextBox1 = vbNullString
            TextBox1.SetFocus
        End If
    Else
        ListBox1.Visible = False
    End If
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    Select Case Len(TextBox1)
        Case 5, 9
            With TextBox1
                .Text = .Text & "-"
                .SelStart = Len(.Text)
            End With
    End Select
End Sub
Private Sub UserForm_Initialize()
    myList = Range("Table6")
    ListBox1.List = myList
End Sub

Private Function GetCutList() As Variant()
    Dim i As Long
    Dim ret() As Variant
    Dim ret2() As Variant
    Dim x As Long
    
    ReDim ret(UBound(myList, 1), 0)
    For i = 1 To UBound(myList, 1)
        If myList(i, 1) Like "*" & TextBox1 & "*" Then
            ret(x, 0) = myList(i, 1)
            x = x + 1
        End If
    Next
    
    If x > 0 Then
        ReDim ret2(x - 1, 0)
        For i = 0 To x - 1
            ret2(i, 0) = ret(i, 0)
        Next
        GetCutList = ret2
    Else
        GetCutList = Array(Empty, Empty)
    End If
End Function

Private Sub CloseForm_Click()
Unload PNForm
End Sub
 
Sheet name is called DATABASE
Part numbers are in column F path in column G

Headers row 1 part number / path start row 2
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
U can trial this untested code...
Code:
'pnform code
Private Sub ListBox1_Click()
Dim Cnt As Integer, Lastrow As Integer
With Sheets("DATABASE")
    Lastrow = .Range("F" & .Rows.Count).End(xlUp).Row
End With
For Cnt = 2 To Lastrow
If Sheets("DATABASE").Range("F" & Cnt).Value = PNForm.ListBox1.Text Then
PNForm.Hide
HondaParts.Show
HondaParts.ImageBox.Picture = LoadPicture(CStr(Sheets("DATABASE").Range("G" & Cnt).Value))
Exit For
End If
Next Cnt
End Sub

'hondaparts userform code
Private Sub CloseForm_Click()
Unload HondaParts
PNForm.Show
End Sub
HTH. Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,214,827
Messages
6,121,820
Members
449,049
Latest member
cybersurfer5000

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