imbed picture in contact form and add button to browse to picture file

R

Rasta

Hi,

I need to customize a contact form to allow the user to click a button and
browse to an image file. When they select the file I want the image imbedded
in the form. Does anyone have any sample code that does this?

Thanks
 
E

Eric Legault [MVP - Outlook]

Here's what you can do:

- Right-click the Toolbox while you are in form design mode, select Custom
Controls and browse to the Microsoft Common Dialog Control. Check it and add
it to the form ("CommonDialog1")
- Add an Image ("Image1") control and a Command Button ("CommandButton1")

Assuming the controls are named properly and are placed on the second page
of the form, this code will prompt the user to choose an image file to load
into the Image control:

Sub CommandButton1_Click()
Dim strPath


Item.GetInspector.ModifiedFormPages("P.2").Controls("CommonDialog1").ShowOpen
strPath =
Item.GetInspector.ModifiedFormPages("P.2").Controls("CommonDialog1").FileName
Set
Item.GetInspector.ModifiedFormPages("P.2").Controls("Image1").Picture =
LoadPicture(strPath)
If Err.Number <> 0 Then
'Problem loading image file
End If
End Sub
 
R

Rasta

Thanks, that worked great except for one thing. When I forward the contact
info to someone in an email, the picture doesn't show up. How can I embed
the picture in the form for each contact?
 
E

Eric Legault [MVP - Outlook]

Sorry, I wasn't thinking - the Picture object is obviously not being saved
with the form. Your only recourse it to assume that the person opening the
form (after a picture has been added to the Contact item previously) has
access to the source file, which you would need to load every time the form
is opened.

This link has an example of how to do this:

http://www.outlookcode.com/d/formpicture.htm

Otherwise, you'd have to save the picture as an attachment to the Contact
item, and when the form opens save the attachment to a file, load it into the
Image control, then delete the file.
 
R

Rasta

Hi,

I think the second option would work, and I don't even need to load the
image into the image control. I just need the user to be able to browse to
the image file and store it as an attachment with each individual contact
item so that it travels with the item if they choose to forward it to
someone.

Do you have some sample code for adding the image file as an attachment to
the contact item?

Thanks
 
E

Eric Legault [MVP - Outlook]

Here's some sample code straight from the Outlook Object Model help file
("C:\Program Files\Microsoft Office\OFFICE11\1033\VBAOL11.CHM"). Just amend
it for your particular needs.

Sub AddAttachment()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
Set myItem = myOlApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add "C:\Test.doc", _
olByValue, 1, "Test"
myItem.Display
End Sub
 
R

Rasta

Thanks

Eric Legault said:
Here's some sample code straight from the Outlook Object Model help file
("C:\Program Files\Microsoft Office\OFFICE11\1033\VBAOL11.CHM"). Just amend
it for your particular needs.

Sub AddAttachment()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
Set myItem = myOlApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add "C:\Test.doc", _
olByValue, 1, "Test"
myItem.Display
End Sub
 

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

Top