Copy a picture from one object to another

P

philippe

Hello,

I'm trying to copy a picture from one object to another as refered in the
following MSDN Library article.
But all what I get is an error telling me that this object can not use the
method or property.
Any idea what's going wrong ?

Thanks,
Philippe
____________________
http://msdn.microsoft.com/library/d...con98/html/vbconaddingpicturestoyourforms.asp

"Copy a picture from one object to another.
Once a picture is loaded or pasted onto a form or into a picture box or
image control, you can assign it to other forms, picture boxes, or image
controls at run time. For example, this statement copies a picture from a
picture box named picDisplay to an image control named imgDisplay:
Set imgDisplay.Picture = picDisplay.Picture"
____________________________


Here is the code I use :
-----------

Function Item_Open()

Set objNameSpace = Item.Application.GetNameSpace("MAPI")
set fold1 = objNameSpace.Folders("Dossiers publics")
set fold2 = fold1.Folders("Tous les dossiers publics")
set fold3 = fold2.Folders("test")
set fold4 = fold3.Folders("oneOffedForms")
Set objContacts = fold4.Items

iNumItems = objContacts.Count


For i = 1 to iNumItems
Set objContact = objContacts.item(i)

If objContact.LastName = item.LastName then set objContactPhotoSource =
objContact

If objContact.LastName = item.LastName then Set item.Image4.Picture =
objContactPhotoSource.stockPhoto.Picture

Next

End Function
-------------------
 
H

Hollis Paul [MVP - Outlook]

But all what I get is an error telling me that this object can not use the
method or property.
Any idea what's going wrong ?
Anytime you create or get an object from an existing source you should test
for its being nothing. From the code you show, you have no idea what
operation is failing. Time to put in some debugging code to find out which
operation that is.
 
P

philippe

Thank you.
The error happens in the statement :
Set item.Image4.Picture = objContactPhotoSource.stockPhoto.Picture
"this object doesn't manage this property or method"

Image4 is an Image Control on the form which is running the script.
objContactPhotoSource is an Image Control on a oneOffed form where I store
photographs.

I checked for the existence of objects (see updated code below)

Note that if there is no match for LastName, i never set nor dim the
objContactPhotoSource by the time I test it with is noting, and that in this
case, I don't get the expected msgBox but "object required" error message.


Function Item_Open()

Set objNameSpace = Item.Application.GetNameSpace("MAPI")
set fold1 = objNameSpace.Folders("Dossiers publics")
set fold2 = fold1.Folders("Tous les dossiers publics")
set fold3 = fold2.Folders("test")
set fold4 = fold3.Folders("oneOffedForms")
Set objContacts = fold4.Items

iNumItems = objContacts.Count


For i = 1 to iNumItems
set objContact = objContacts.item(i)

msgbox("boucle : " & i)
if objContacts is nothing then msgbox("objContacts is nothing")
if objContact is nothing then msgbox("objContact is nothing")

If objContact.LastName = item.LastName then msgBox("last name match")
If objContact.LastName = item.LastName then set objContactPhotoSource =
objContact
if objContactPhotoSource is nothing then msgbox("objContactPhotoSource is
nothing")

If objContact.LastName = item.LastName then Set item.Image4.Picture =
objContactPhotoSource.stockPhoto.Picture
'if item.Image4.Picture is nothing then msgbox("item.Image4.Picture")

Next
End Function
"Hollis Paul [MVP - Outlook]" a écrit :
 
H

Hollis Paul [MVP - Outlook]

Set item.Image4.Picture = objContactPhotoSource.stockPhoto.Picture
"this object doesn't manage this property or method"
You know, not using the explicit directive always bites you in the end.
And I think using compound object specifications has the same
characteristics. I think you have been bitten by the fact that
stockPhoto was never defined as a control. I don't know what it would
infer stockPhoto is, given that it is encountering the name for the
first time.

It has been a long time since I have done a lot of programming, and I
do not even recognize what form of vb you are using. But when I was
programming, we had to get the controls object from the item, and find
the specific control object from the collection.

Take a look at the following web page:

Syntax for Microsoft Outlook property and control values and events
8/9/2005
Correct syntax for accessing Microsoft Outlook property and control
values and writing events that respond to changes in properties or
control values
http://www.outlookcode.com/d/propsyntax.htm - 31 KB
 

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