PDA

View Full Version : Solved: Notifying changes in Post



Shellgrip
10-11-2005, 04:04 AM
Hi, I'm sure this is dead simple but I'm completely confused by Outlook and am struggling to work out what is called what and... well, I need help.

I have a custom IPM.Post form and on it are three check boxes. All I want is for a mail to be sent when these check boxes change their value. To simplify installation I need the code to be embedded with the form as a script, not an Outlook VBA routine.

So far I have this:


Sub Item_CustomPropertyChange(ByVal Name)
Set olApp = CreateObject("Outlook.Application")
Set olNameSpace = OlApp.GetNameSpace("MAPI")

Select Case Name
Case "Collection booked"
Set MailNoti = OlApp.CreateItem(0)
MailNoti.To = "jon@mycompany.com"
MailNoti.Subject = "Collection Booked"
Message = "Your Shipping Request to has been booked!"
MailNoti.Body = Message
MailNoti.Send
End Select

End Sub


Which works (I'll add more Case statements once I've got one working!), but what I really need is a) for the email address to be the original poster of the form, b) for the Message body to include the Subject field on that form (as part of a sentence).

I know I need to reference the form in some way to find the 'sender' and the subject but I'm lost as to how. Can anyone help?

FYI the form is called IPM.Post.ShipReq
Jon

Shellgrip
10-25-2005, 07:11 AM
Nobody got any advice on this?

Jon

chocobochick
10-25-2005, 10:39 AM
I try to avoid VBScript whenever I can, but I can understand how it is desirable in this situation.

First of all, using a macro to retrieve a sender's email address in Outlook can be a painful and ugly process. The SenderEmailAddress property for an item is only available in Outlook 2003 and later, and thanks to a security patch, chances are you'll see a popup window asking for explicit authorization to share those addresses with the "unknown program" for a few minutes. In this case, you're either stuck with manually clicking the Yes button each time or you'll need to research and install additional software to bypass or automate this popup for you.

Secondly, my personal preference is to retrieve item information from the item's object, not from the form. To do this, you can retrieve the object reference from the Inspector object (the form), and since that Inspector is already open, you can find the Application's ActiveInspector like so:

Set objPostItem = Application.ActiveInspector.CurrentItem
MailNoti.To = objPostItem.SenderEmailAddress
MailNoti.Body = objPostItem.Subject & vbCrLf & Message


I hope that helps!

Shellgrip
10-27-2005, 08:31 AM
Chocobo, that's the trick! :thumb

Thanks muchly, that's the pointer I needed. No excuse for not getting the project finished now.

Jon