How to view an item Image in a Userform from a saved Image Folder

michaelroshan

New Member
Joined
Jun 27, 2020
Messages
16
Office Version
  1. 2007
Platform
  1. Windows
I have a workbook that has 1500 itmes as inventory and items going out and coming in everyday.
I have a userform which i have bult to manage this with ease all items linked to an itemcode. I would like to display the item image as well in the same userform when item is recalled by item code using comboBox. how can i do this?
know there is a method where we can store all images in a folder and all items names with the matching item code but i have no clue how to link them with VBA and display it on the user form.
Can you help on this?
 

Attachments

  • xxxx.png
    xxxx.png
    40 KB · Views: 66

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hello Michaelroshan,
in the same folder put all images.
Fill the combobox rowsource with names of your files.
Take care your images have same extension.
Change path in this code to the location of your folder and try...
VBA Code:
Private Sub ComboBox1_Change()

     On Error GoTo EX:
     Me.Image1.Picture = LoadPicture("C:\" & Me.ComboBox1.Value & ".jpg")
EX:

End Sub
 
Upvote 0
Hello Michaelroshan,
in the same folder put all images.
Fill the combobox rowsource with names of your files.
Take care your images have same extension.
Change path in this code to the location of your folder and try...
VBA Code:
Private Sub ComboBox1_Change()

     On Error GoTo EX:
     Me.Image1.Picture = LoadPicture("C:\" & Me.ComboBox1.Value & ".jpg")
EX:

End Sub
Hi Sir, Many Thanks for your response but i am actually stuck as to where i can insert this code.

the fllowing is the code i have so far for the userform as of now, I added your code right at the bottom of the following code and changed the path and names of the images to match.

but it dose not show in the imagebox in the userform!

am i doing something wrong somewhere?


Private Sub ItemBox_Change()
RunObject Me.ItemBox
End Sub
Private Sub CCBox_Change()
RunObject Me.CCBox
End Sub
Private Sub MonthBox_Change()
RunObject Me.MonthBox
End Sub
Private Sub NameBox_Change()
RunObject Me.NameBox
End Sub
Private Sub RunObject(Object)
Dim sr As String
Dim nm As String
Dim lookupRange As Range
'Dim ItemBox As Variant
'Dim MonthBox As Variant
'Dim CCBox As Variant
Set lookupRange = Worksheets("Sheet1").Range("$A$5:$CWI$7000")
'If Me.ItemBox.Value = "" Then
'MsgBox "Please Enter Item Code to Update!!!", vbExclamation, "Item Code!"
'Exit Sub
'End If
sr = Me.ItemBox.Value
nm = Me.NameBox.Value
On Error Resume Next
Me.ItemBox.Value = Application.WorksheetFunction.VLookup(nm, lookupRange, 1, 0)
Me.NameBox.Value = Application.WorksheetFunction.VLookup(sr, lookupRange, 2, 0)
Me.UnitBox.Value = Application.WorksheetFunction.VLookup(sr, lookupRange, 3, 0)
Me.Label16 = Application.WorksheetFunction.VLookup(sr, lookupRange, 126, 0)
 
Upvote 0
Here...
VBA Code:
Private Sub RunObject(Object)
  
    Dim sr As String
    Dim nm As String
    Dim lookupRange As range
    'Dim ItemBox As Variant
    'Dim MonthBox As Variant
    'Dim CCBox As Variant
    Set lookupRange = Worksheets("Sheet1").range("$A$5:$CWI$7000")
    'If Me.ItemBox.Value = "" Then
    'MsgBox "Please Enter Item Code to Update!!!", vbExclamation, "Item Code!"
    'Exit Sub
    'End If
  
    On Error Resume Next
    Me.ItemBox.Value = Application.WorksheetFunction.VLookup(nm, lookupRange, 1, 0)
    Me.NameBox.Value = Application.WorksheetFunction.VLookup(sr, lookupRange, 2, 0)
'    Me.UnitBox.Value = Application.WorksheetFunction.VLookup(sr, lookupRange, 3, 0)
'    Me.Label16 = Application.WorksheetFunction.VLookup(sr, lookupRange, 126, 0)

    sr = Me.ItemBox.Value
    nm = Me.NameBox.Value
    Me.Image1.Picture = LoadPicture("C:\" & nm & ".jpg")

End Sub
 
Upvote 0
Sorry my mistake...

VBA Code:
Private Sub RunObject(Object)

   Dim sr As String
   Dim nm As String
   Dim lookupRange As range
   'Dim ItemBox As Variant
   'Dim MonthBox As Variant
   'Dim CCBox As Variant
   Set lookupRange = Worksheets("Sheet1").range("$A$5:$CWI$7000")
   'If Me.ItemBox.Value = "" Then
   'MsgBox "Please Enter Item Code to Update!!!", vbExclamation, "Item Code!"
   'Exit Sub
   'End If

   sr = Me.ItemBox.Value
   nm = Me.NameBox.Value

   On Error Resume Next
   Me.ItemBox.Value = Application.WorksheetFunction.VLookup(nm, lookupRange, 1, 0)
   Me.NameBox.Value = Application.WorksheetFunction.VLookup(sr, lookupRange, 2, 0)
  ' Me.UnitBox.Value = Application.WorksheetFunction.VLookup(sr, lookupRange, 3, 0)
  ' Me.Label16 = Application.WorksheetFunction.VLookup(sr, lookupRange, 126, 0)

   Me.Image1.Picture = LoadPicture("C:\" & nm & ".jpg")

End Sub

Be sure that VLookup finding this name in the sheet.
 
Last edited:
Upvote 0
Also replace variables places.
Change...
VBA Code:
   Me.ItemBox.Value = Application.WorksheetFunction.VLookup(nm, lookupRange, 1, 0)
   Me.NameBox.Value = Application.WorksheetFunction.VLookup(sr, lookupRange, 2, 0)
to
VBA Code:
   Me.ItemBox.Value = Application.WorksheetFunction.VLookup(sr, lookupRange, 1, 0)
   Me.NameBox.Value = Application.WorksheetFunction.VLookup(nm, lookupRange, 2, 0)
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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