PDA

View Full Version : Show picture in Userform



lhtqasonline
06-22-2009, 02:39 AM
Hi

I need to show a picture of person in a userform.
The userform is a employee database.

I used Application.Match to view data from a spreadsheet in the userform.

What I now need to do is load the id foto of the person in the image box on my userform.

I tried the following code (snipped from code found in this website)
Me.EmplNo is the one i would like to use to match with the picture file
I named the picture (stored in the same directory) to match the EmplNo field.

Private Sub Show_Pic()

Dim EmpFound As Range
Dim fPath As String
Set EmpFound = Me.EmplNo
On Error Resume Next
If EmpFound Is Nothing Then
Image2.Picture = LoadPicture(fPath & "nopic.gif")
Else
With EmpFound
'Look in the directory where this workbook is located.
fPath = ThisWorkbook.Path & "\"
On Error Resume Next
'If a matching picture is found then display it.
Image2.Picture = LoadPicture(fPath & "\" & ListBox1.Value & ".jpg")
'If No picture found then display the default picture.
If Err = 0 Then Exit Sub
Image2.Picture = LoadPicture(fPath & "nopic.gif")
End If
End With
End Sub


Please help

Bob Phillips
06-22-2009, 05:29 AM
See http://www.oaltd.co.uk/Excel/Default.htm and scroll down to a file called PastePicture.zip.

p45cal
06-22-2009, 05:37 AM
What type of control is Me.EmplNo ?

lhtqasonline
06-22-2009, 06:06 AM
Me.EmplNo is the name of the textbox in the userform

jolivanes
06-22-2009, 08:23 AM
Someone else was kind enough to make this file to help.
See if it can be adapted to what you want.

HTH
John

lhtqasonline
06-23-2009, 03:26 AM
Thanks Jolivanes I will check it out and report back

lhtqasonline
07-01-2009, 02:32 AM
Hi guys
No luck so far using any of the suggestions. I know to little of VBA to explain myself, will try and create a dummy spreadsheet as the information i'm working with is sensitive information.

Dodgeitorels
10-05-2009, 07:39 AM
I had image issues but found a solution. Maybe part of it will help you. My userform is in this post http://www.vbaexpress.com/forum/showthread.php?t=28238&highlight=userform+to+input+data (http://www.vbaexpress.com/forum/showthread.php?t=28238&highlight=userform+to+input+data)

Go to llast post for working file (take note of where to put images)

hope it helps.

lhtqasonline
10-05-2009, 11:12 PM
Hi Dodgeitorels
Thank you for your post, I will let you know if it works for me.

Regards,
Leon