Before Send

B

BigDubb

How would one prevent sending of an appontment object if all of the required
fields haven't been completed? I cant seem to find a before send event to
trap on.

Thanks.
 
K

Ken Slovak - [MVP - Outlook]

That's because there isn't such an event. However, the item.Send() event
does have a Cancel argument. Set that to True and that will cancel the send.
 
B

BigDubb

Thanks.

Actually I was able to get the Application object from the AppointmentItem
and add a handler on the ItemSend event, which is exactly what I was looking
for.

One caveat with this though, it seems to reload the send event when a
messagebox is shown, to notify the user as to why the request can't be sent.
 
B

BigDubb

Another issue with this event....

If a user is attempting to cancel the request and a required value is not
set, then the send event is never executed.
 
B

BigDubb

Ok...

The more I dig into this the more odd things react.

It appears as if the Send button on a Meeting/Appointment request fires off
a Send Event for every recipient on the appointment.

which after thinking about it, makes sense. However, how do I get my
UserDefined variables passed into the new appointment object for each
recipient?

This is a .Net C# solution.

What I"m doing so far.

On the FormRegionShowing method I added hooked a method to the current
application object.

_appt.Application.ItemSend += new
Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend)

Then in the method the handler references I test on a local variable

if (!_Qualified)
e.Cancel;


where _Qualified is a boolean value, that is set based on other criteria on
the form.

This feels like the correct implementation, but isn't reacting the right way.
 
B

BigDubb

There is no Item object in the parameters, nor understood by the class
associated to the new region.

Can you clarify further?

Again, this is not a VBA project, it is a VS2008 C# project.
 
K

Ken Slovak - [MVP - Outlook]

It doesn't matter what type of project it is, it's still using the Outlook
object model.

If you have an appointment item you have an item. AppointmentItem has a Send
event that you can handle. Look at the object browser.
 
B

BigDubb

I am not seeing an Appointment.Send Event, rather an Send Method.

When trying to make the event handler for the send method I get the
following error
"Cannot assign to 'Send' because it is a 'method group' "

Here is the syntax
AppointmentItem _appt = this.OutlookItem as Outlook.AppointmentItem;
if(_appt == null)
return;

_appt.Send += new
Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);


What am I missing?
 
K

Ken Slovak - [MVP - Outlook]

What you're missing is what you're going to run into with methods/events
that overload the same keyword in all managed code. In this case
AppointmentItem doesn't directly expose the Send event since it uses the
same keyword as the Send method.

There are a couple of ways to do what you need to do:

1. Declare at class level an ItemEvents_Event object, say _apptEvents:
private Outlook.ItemEvents_Event _apptEvents;

Then instantiate the event handler so:
_apptEvents = (Outlook.ItemEvents_Event)_appt;
_apptEvents.Send += new Outlook.ItemEvents_SendEventHandler(myHandler);

2. An alternative is to use AppointmentItemClass:
private Outlook.AppointmentItemClass _itemClass; // class level

Then instantiate as follows:
_itemClass = (Outlook.AppointmentItemClass) _appt;
_itemClass.ItemEvents_10_Event_Send += etc.
 
B

BigDubb

Ken,

First off thanks for the suggestion, I took your first approach and this
worked well. However, we seem to have hit an issue with send event.

For some users, meeting requests are sent twice. It is sent once when the
meeting is set up and the send button is clicked and the meeting is
'qualified' (our methodology), then when users close and reopen outlook, the
request is sent again.

I am trapping the event as follows:
_apptEvents.Send += new
Microsoft.Office.Interop.Outlook.ItemEvents_SendEventHandler(_apptEvents_Send);

which is fired off during the FormRegionShowing event.

In the _apptEvents_Send method I just do some checking to see if the meeting
has been 'qualified' and cancel respectively.

private voide _apptEvents_Send(ref bool Cancel)
{
if(!Qualified)
{
messagebox.show("Meeting not qualified");
Cancel = true;
return;
}
}

Any ideas?
 
K

Ken Slovak - [MVP - Outlook]

No idea. You mention in your post in the other group that this happens only
with some users. Start from there. What's different about those users setups
or what they're also running that integrates with Outlook? Add more logging
to your code also in places where it's appropriate to see what's going on.
For example, on startup are any items still in the Outbox, that sort of
thing.
 

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