Best way to get data from Item before send?

D

djohnson

Hello, I'm now on my first custom Outlook Form. It's nothing fancy.
It's just code on the sender's end. So I am using olMailItem to send
mail to avoid sending the entire form so the recipient does not get a
"cannot view in the reading pane" message. I've just added a few
fields to the Message Form that transfer selection to the text in the
body. That is working fine. The problem happens during the send
command.

On computers other than my own, on a seemingly sporadic basis, they get
the error "outlook does not recognize one or more names" I have read
about this possibly being a corrupt address book problem, but I don't
know if that is the case. I think there might be something wrong with
my code. I'm particularly uncertain about "olmail.To = Item.To" and
"olmail.CC = Item.CC". Can I do that? If not, how? If this does
involve the address book is it possible to detect which names are not
being found?

Another big question is, is there any better way to avoid receipients
getting a message about code in their reading pane than what I'm doing?

Anyway, here is what I'm doing... maybe someone could point me in the
right direction?



Function Item_Send()
'On Error Resume Next
Set olapp = CreateObject("Outlook.Application")
Set olmail = olapp.CreateItem(olMailItem)
With olMail
olmail.To = Item.To
olmail.CC = Item.CC
olmail.Subject = Item.Subject
olmail.body = Item.Body
olmail.Send
End With

Set objInsp = Item.GetInspector
objInsp.Close 1
End Function
 
D

djohnson

I would like to add a couple things....

The main problem is the error "could not recognize one or more names".
If the error is in fact a result of PST file corruption I am not sure
how to run scanpst.exe when, in our case, there is not local PST file
that I can find since the information is stored on the Exchange server.
Could someone tell me what file should be scanned? Thank you...
 
S

Sue Mosher [MVP-Outlook]

Instead of using To, you should call Item.Recipients.ResolveAll on the
original item, and if that returns True, iterate the Item.Recipients
collection and create matchin recipients on the new outgoing item.

Never use CreateObject to create a new Outlook.Application object in your
custom form code. Use the intrinsic Application object that is already
available to you.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
D

djohnson

Sue said:
Instead of using To, you should call Item.Recipients.ResolveAll on the
original item, and if that returns True, iterate the Item.Recipients
collection and create matchin recipients on the new outgoing item.


I did that; thanks for the advice.

Never use CreateObject to create a new Outlook.Application object in your
custom form code. Use the intrinsic Application object that is already
available to you.

Would the intrinsic Application object be the Form Item? Maybe I
misunderstand. It was my understanding that this would send the whole
form including the code and end up creating a pane warning on the
recipients' end, which I was trying to avoid (not sure who would want
that). Since I only need code on the sender's end I don't want to send
the whole form.
 
K

Ken Slovak - [MVP - Outlook]

In any open form you have 2 intrinsic objects you never have to declare or
instantiate: Item (the form) and Application (the Outlook.Application
object). So you don't use CreateObject to get a handle to
Outlook.Application, you use the intrinsic Application object of the form.
 

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