Display contact photos

  • Thread starter Thread starter Eric F
  • Start date Start date
E

Eric F

Can someone shed some light on an easy way to display contact photos for
each contact that contains a picture on a network drive. I would like to see
some code that will display the picture using the a path. The pictures are
named the same as the ContactID. I.e. 1234.jpg (1234 = ContactID number).
Any thoughts would be great.

TY
Eric
 
Yes that can be done quite easily.
Use the "Image" tool that can be found on the toolbar...

1) Drag it onto you form, to the size you want...
2) just humor the request for a picture and put a dummy one in with the
browser
(preferrably a jpeg or bitmap, stay away from GIF)
3) Name your Image something better than Image1 (imgContactPhoto)...
4) quite literally your code will be
imageContactPhoto.picture = "c:\photos\contact1.jpg"

insert this code into the current event of the form.

Voila! The photo in the path for the record will bring up the photo
and your database won't be croweded with anything but a text reference to a
path.

Hope you are successful. Let me know. I have more tricks, but let me know
when you get this working!
 
Thanks for the quick reply. I think you had intentions of puting some code
in this email? I am still in need of a solution to have the picture change
when I change the contact or just show a blank if no picture is on file. Any
help would be great. Thank you.
 
In the form's "Current" event

Place the following code (This is assuming you have placed the image holder
and named it something like ContactPic - oh and also assuming you have a
ContactDetail form with all their information that you want to relate this to)

Private Sub Form_Current
dim PathToPhoto as string
dim ContactPhoto as string
PathToPhoto = "D:\MyContactPhotos....wherever your path is"
ConactPhoto = Me.ContactID & ".jpg"
'(try to be consistent in whatever format you decide)


If len(PathToPhoto & "\" & Me.ContactID & ".jpg") <> 0 then
ContactPic.Picture = ContactPhoto
Else
ContactPic.Picture = ""

'(Or you could have a picture of your company logo here "CompanyLogo.jpg")
End If

This process will make it so all you have to do, is acquire that photo from
your contact, and put it in the folder named ContactID.jpg (for each
different Contact)
Example 434.jpg, 435.jpg etc..

When you delete their photo, the program will automatically display the
CompanyLogo.jpg

This can be tweaked a little more, but should suffice.
When you test it after you have acquired at least 2 or 3 photos, try moving
through each contact record - You will notice the contacts picture changing
for each contact if you PageDown or click your 'Next' button through your
Details form.
 
This works great...Thanks. The only problem I am having is I get an error if
I don't have a pic for all the contacts. Is there some code I can put in to
show nothing is a contact has no pic?
 
This works great...Thanks. The only problem I am having is I get an error if
I don't have a pic for all the contacts. Is there some code I can put in to
show nothing is a contact has no pic?
 
Try the following...
Create a picture called "Blank.jpg" with your favorite photo editor
(photoshop etc.)
For the "else" portion of the IF statement. It could be plain gray, white,
or a company logo.
I'm figuring this should be enough to prevent an error, but
I even added error handling just in case -
(look at the error number you receive when you get this error and use it
below)

Then use the following, in your current event:
Private Sub Form_Current
On Error GoTo EH
If len(PathToPhoto & "\" & Me.ContactID & ".jpg") <> 0 then
ContactPic.Picture = ContactPhoto
Else
ContactPic.Picture = PathToPhoto & "\" & "Blank.jpg"
End If

Exit Sub
EH:
Select Case Err
case 52,62 '(or whatever number you see)
ContactPic.Picture = PathToPhoto & "\" & "Blank.jpg"
msgbox "No picture available"
end select
End Sub

Just keep playing around with this.. you'll get it soon.
 
Good morning,

I first want to thank you for helping me on this. It is almost working 100%.
I have one more issue... Upon opening the project the pictures will not
display, almost like it has lost connection with the path. The pictures are
contained on a network drive. If I go into the properties of the picture box
and click on the picture path it will work. But of course doesnt when I have
closed and reopened the DB. Below is the code I am using.

Private Sub Form_Current()
On Error GoTo Err_NoPic
Dim PathToPhoto As String
Dim ContactPhoto As String
PathToPhoto = "I:\NAIOP_Website\images\Members"
ContactPhoto = Me.ContactID & ".jpg"

If Len(PathToPhoto & "\" & Me.ContactID & ".jpg") <> 0 Then
ContactPic.Picture = ContactPhoto
Else
ContactPic.Picture = "I:\NAIOP_Website\images\Members\nopic.jpg"
End If

Err_NoPic:
Select Case Err
Case 2220
ContactPic.Picture = "I:\NAIOP_Website\images\Members\nopic.jpg"
End Select
End Sub
 
Good morning. You caught me on the way to work. I'm glad it's almost 100%
My application is similar, but when I answered your questions, I tried to
improve on my design.

Just curious. After you open, if you move to the next record does a picture
display?
If so, try one more thing and if that doesn't work, I'll see if I can look
at it tonight.

in your "Load" event put the following line:

call form_current

This will call the same code when the form loads.

and the current event will take over for every subsequent record you look at.
(I noticed that I did this in my application, but I thought it was redundant
)- I assumed the current event takes place in the Load Event as well. So try
this... again if it doesn't work, I'll help you until it does!
 
This may also shed some light on the problem. I can see an error box flash
and clearly there is a nopic.jpg in the spot. So I know it is calling the
right path. Problem must lie in the link from the Picture box. I have tried
leaving the pic box link to (none) and also with the path to no avail.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top