Item_Send: How to generate a non-custom form message from custom f

G

Guest

I noticed a brief reference in a previous posting about using code in a
custom form's Item_Send event handler to generate a new, non-custom-form
message. I need to do exactly this. How can I accomplish this? I am
relatively new to VBA in Outlook, so treat me as a novice. Thank you!
 
S

Sue Mosher [MVP-Outlook]

It would be VBScript code, not VBA, because that's what Outlook custom forms use, and would look something like this, to create a new plain text message. Note that you need to add CopyAtts subroutine from http://www.outlookcode.com/d/code/copyatts.htm to this script.

Function Item_Send()
Dim objMsg ' As Outlook.MailItem
Dim objRecip ' As Outlook.Recipient
Dim objNewRecip ' As Outlook.Recipient
Const olMailItem = 0
Const olFormatPlain = 1
On Error Resume Next
Item_Send = False
Set objMsg = Application.CreateItem(olMailItem)
For Each objRecip In Item.Recipients
Set objNewRecip = _
objMsg.Recipients.Add(objRecip.address)
If objNewRecip.Resolve Then
objNewRecip.Type = objRecip.Type
End If
Next
If Item.Attachments.Count > 0 Then
' Add CopyAtts function from
' http://www.outlookcode.com/d/code/copyatts.htm
' to this script.
Call CopyAtts(Item, objMsg)
End If
With objMsg
.BodyFormat = olFormatPlain
.Body = Item.Body
.DeferredDeliveryTime = Item.DeferredDeliveryTime
.DeleteAfterSubmit = Item.DeleteAfterSubmit
.ExpiryTime = Item.ExpiryTime
.Importance = Item.Importance
.OriginatorDeliveryReportRequested = _
Item.OriginatorDeliveryReportRequested
.ReadReceiptRequested = _
Item.ReadReceiptRequested
.Subject = Item.Subject
If .Recipients.count > 0 _
And .Recipients.ResolveAll Then
.Send
MsgBox "Message sent successfully. " & _
"You can close the original now."
Else
.Display
End If
End With
Set objMsg = Nothing
Set objRecip = Nothing
Set objNewRecip = Nothing
End Function

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Thank you, Sue. I ran this code in a custom form (without the CopyAtts
subroutine), and it appeared to run. I got the successful message at the end
of the script. However, the message that was received on the other end was
blank. Do I need to customize any of the script? I just ran it as it is.
 
S

Sue Mosher [MVP-Outlook]

After the code sets the Body property, you might want to throw in a MsgBox objMsg.Body statement to see what Outlook thinks the new message body contains. Also make sure you're up-to-date on Outlook patches, since there have been some blank message issues in some versions.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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