Form - Specific "To" Recipient value

D

daniel_l_v

Created a simple "Phone Message" style custom Outlook 2007 form.
Want to set the "To" field to a specific email address that customers cannot
change, have not been able to do this.

Can anyone advise whether the "To" field can be set programmatically prior
to the message being sent, so that it always gets sent to the same recipient?
 
S

Sue Mosher [MVP]

Sure, that's possible. Remove the address controls from the form and try
this code:

Function Item_Open()
If Item.Sent <> False Then
Item.To = "(e-mail address removed)"
Item.Recipients.ResolveAll
End If
End Function

Function Item_Send()
Item.To = "(e-mail address removed)"
End Function

The Item.To statement is in both events to make sure there's a recipient
already present when the user tries to send the item. This won't prevent a
user from bringing up the Address Book dialog and changing the recipients,
but the Item_Send code will override any changes they've made.

You are planning to publish this form to the Organizational Forms library or
to each user's Personal Forms library, correct?
 
D

daniel_l_v

Hi Sue,

Thanks for the code.

I've put the code you suggested in the script editor and saved my form.

However, whilst the code doesn't give any errors, it doesn't seem to
actually trigger. I've put in a couple of MsgBox statesments to check, but
neither seems to run.

Yes - The form will be published eventually to Organizational Forms.

Is there something I might me missing that could be stopping the code from
actually running? Do I need any header or tags in the script to ensure it is
in the correct format?

Just checking, I should be putting the code in the "View Code" Script
Editor, and NOT in a Visual Basic project.
 
S

Sue Mosher [MVP]

I don't know what you mean by "saved my form." Code runs only on published
forms. You'll need to publish it to get it to work.
 
D

daniel_l_v

Sue, by "save my form" I meant exactly that, you can save a form as an OFT
file whilst working on it.

I've published but still not working.

Is the "Item" an object representing the message itself? I can't find
"Item" in the VB Script Object Browser.
 
S

Sue Mosher [MVP]

As I said, only published forms run code. Forms saved as .oft files don't.

Item is an intrinsic object in custom form code representing the current
item, just as Application represents the running Outlook.Application object.
 

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