Load Picture based on a combobox value

El Interino

New Member
Joined
Jan 12, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm having a hard time figuring out how I can load a picture on an image control box based on the value of the combo box.

I want to show a picture of a person according to what's shown on the combo box. The combo box is currently used for another function but I want to use it as well to show the image. Another thing, I have the rowsource on another sheet.

Anything I can do? Your help matters. Thanks!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Where are the pictures?
 
Upvote 0
Thanks for responding, Rory.

I am actually thinking if I could put them in the worksheet or if it is possible to use the file path from where it is located.
 
Upvote 0
File path is easier - you just use LoadPicture with the full path and filename:

Code:
Me.Image1.picture = loadpicture("C:\some path here\" & me.combobox1.value)

for example.
 
Upvote 0
File path is easier - you just use LoadPicture with the full path and filename:

Code:
Me.Image1.picture = loadpicture("C:\some path here\" & me.combobox1.value)

for example.
Thanks, Rory. Will it be possible to use an existing combo box and command for such a purpose? I have a roster of people so I would need to make sure their corresponding photo display is based on selection on combo box.
 
Upvote 0
Yes - the idea is that you substitute the names of your actual controls into that code. ;)
 
Upvote 0
What error, and what is the full code you are using?
 
Upvote 0
Here. I think I wrongly placed the code or something. Notice that I also placed the RowSource based on another sheet which is Photos!A3:a36
 

Attachments

  • Capture1.JPG
    Capture1.JPG
    214.6 KB · Views: 6
  • Capture2.JPG
    Capture2.JPG
    126.4 KB · Views: 6
  • Capture3.JPG
    Capture3.JPG
    181.3 KB · Views: 6
Upvote 0
Here is the code under the save button:

Private Sub cmdSave_Click()

Dim msgValue As VbMsgBoxResult

msgValue = MsgBox("Sure ka na ba? Save mo na!", vbYesNo + vbInformation, "Confirmation")

If msgValue = vbNo Then Exit Sub

If ValidateEntries = True Then


Call Submit
Call Reset
End If

On Error Resume Next

If cmbEmployeeName.ListIndex = 0 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\ABUNDABAR, Rene II B..jpg")
Else
If cmbEmployeeName.ListIndex = 1 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\ADAYO, Manuel Jr. D..jpg")
Else
If cmbEmployeeName.ListIndex = 2 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\ARTIAGA, Jay Jose S..jpg")
Else
If cmbEmployeeName.ListIndex = 3 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\BALVERDE, Jecamia B..jpg ")
Else
If cmbEmployeeName.ListIndex = 4 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\BELANO, Lilibeth R..jpg")
Else
If cmbEmployeeName.ListIndex = 5 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\BODOLLO, Francis G..jpg")
Else
If cmbEmployeeName.ListIndex = 6 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\BOMBASE, Carmela M.jpg")
Else
If cmbEmployeeName.ListIndex = 7 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\BOÑAGA, Rocel R..jpg")
Else
If cmbEmployeeName.ListIndex = 8 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\BONGYAD, Venus F...jpg")
Else
If cmbEmployeeName.ListIndex = 9 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\CIRUJALES, Josephine B..jpg")
Else
If cmbEmployeeName.ListIndex = 10 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\CONING, Michelle T..jpg")
Else
If cmbEmployeeName.ListIndex = 11 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\CONTANTE, Maria Corazon B..jpg")
Else
If cmbEmployeeName.ListIndex = 12 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\CORONEL, Charibel R..jpg")
Else
If cmbEmployeeName.ListIndex = 13 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\DEPAGO, Hershon S..jpg")
Else
If cmbEmployeeName.ListIndex = 14 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\EGUIA, Bonnie Vic M.jpg")
Else
If cmbEmployeeName.ListIndex = 15 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\LOPEZ, Santiago Jr. B.jpg")
Else
If cmbEmployeeName.ListIndex = 16 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\MABANA, Joven C..jpg")
Else
If cmbEmployeeName.ListIndex = 17 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\MANLANGIT, Grace Shiela P..jpg")
Else
If cmbEmployeeName.ListIndex = 18 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\MORTE, Ernesto Jr. M..jpg")
Else
If cmbEmployeeName.ListIndex = 19 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\OBIÑA, Mike Angelo A..jpg")
Else
If cmbEmployeeName.ListIndex = 20 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\ORDOÑEZ, Eden S..jpg")
Else
If cmbEmployeeName.ListIndex = 21 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\PACAY, Jesica B..jpg")
Else
If cmbEmployeeName.ListIndex = 22 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\PANCHO, Rubelyn I..jpg")
Else
If cmbEmployeeName.ListIndex = 23 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\PEREZ, Mailou B..jpg")
Else
If cmbEmployeeName.ListIndex = 24 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\QUINGQUING, Maricel B..jpg")
Else
If cmbEmployeeName.ListIndex = 25 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\SATINGUIN, Ma. Myla A..jpg")
Else
If cmbEmployeeName.ListIndex = 26 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\SORETA, Yolanda M..jpg")
Else
If cmbEmployeeName.ListIndex = 27 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\TEXON, Ivy Mae P..jpg")
Else
If cmbEmployeeName.ListIndex = 28 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\VILLAMOR, Marilyn C..jpg")
Else
If cmbEmployeeName.ListIndex = 29 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\VILLANO, Eunice A.jpg")
Else
If cmbEmployeeName.ListIndex = 30 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\VIÑAS, Tito B.jpg")
Else
If cmbEmployeeName.ListIndex = 31 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\BATUCAN, Joel P..jpg")
Else
If cmbEmployeeName.ListIndex = 32 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\DE LOS SANTOS, Sandra P..jpg")
Else
If cmbEmployeeName.ListIndex = 33 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\INTERINO, Lino III D..jpg")
Else
If cmbEmployeeName.ListIndex = 34 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\PALOMA, Jessica N.jpg")
Else
If cmbEmployeeName.ListIndex = 35 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\PANCHO, Rubelyn I..jpg")
Else
If cmbEmployeeName.ListIndex = 36 Then
Image1.Picture = LoadPicture("C:\Users\linoi\OneDrive - DEPED REGION 5-2\Desktop\TKS\PANCHO, Rubelyn I..jpg")

End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

End Sub


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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