getitemfromid and outlook reminders

F

Foths Mylo

Hallo my friends.

I ve searched enough newsgroups and internet sites, but didnt find any
reference to my problem.
i dont know if what im facing is specific to my installation, or a common
problem.
I'm trying to set reminders for apointments in the default calendar folder
of Outlook.
But i dont set them, as soon as i create the apointment. Instead, the
apointment is stored with no reminder at all, and later i open it and
process it, adding the reminder.
For this usage, i use the function "getitemfromid".
My code, is in Delphi, so for the majority of VB or VBA programers here, im
making some comments, although of course the object model is the same.

try
CoInitialize(nil); <----initialize com
objOL:=CoOutlookApplication.Create; <-----create the outlook aplication
ns:=objOL.GetNamespace('MAPI'); <-----get the namespace
myappf:=ns.GetDefaultFolder(olFolderCalendar); <-----get the default
calendar folder
objAppt:=ns.GetItemFromID(REminderID,myappf.StoreID) as AppointmentItem;
<-------------get the stored apointment item from the calendar folder
With objAppt do begin
//objAppt.Display(false); <---------this line is comented out (i dont
want the apoinment actually displayed) and unfortunately is the only
workaround i found so far, to my problem
ReminderMinutesBeforeStart:=(60 * 23) + 59; <--------set a reminder
time
ReminderSet:= True; <--------activate the item
objAppt.Save; <----save the reminder
//objAppt.Close(olSave); <-----------comented out as well
End;
finally
ns:=nil;
objOL:=nil;
objAppt:=nil;
couninitialize;
end;

i would like to ask, if some of you have faced the same situation:
If i set a reminder as soon as the apointment is created, everything seems
to be working fine.
If i create the apoitnment with no reminder, and then use my code, what
happens is this:

Everything seem to be stored perfectly ok, the reminder option is checked,
the time of the reminder is set as well, but no matter how long i wait for,
the reminder never comes up.
The only workaround for the reminder to come up, after editing the
apointment with GETITEMFROMID, is to display the item, change the properties
i need, save settings, and close the item.
But i dont want it to work this way, i would like all this process to happen
in the background, without the PC user seeing screens poping up for few
seconds and then disapearing.

Do you have any sugestions, any other workarounds?

THank you very much, in advance.
 
K

Ken Slovak - [MVP - Outlook]

Are these single appointments or recurring appointments? Each would
have to treated differently. For a recurring appointment you'd have to
get the master appointment first before you set reminder properties.
You would test for IsRecurring and if True you would use the
GetRecurrencePattern method to get that object and then
RecurrencePattern.Parent to get the master appointment item.

As far as I know just setting ReminderMinutesBeforeStart is not
sufficient for setting a reminder for an existing item. You must set
the FlagDueBy property and the ReminderTime property, neither of which
is exposed in the Outlook object model. In CDO 1.21 or Extended MAPI
or Redemption terms those properties would be:
ReminderTime: {00062008-0000-0000-C000-000000000046}0x8502
FlagDueBy: {00062008-0000-0000-C000-000000000046}0x8560

Since those properties aren't exposed to the Outlook object model you
would need to use CDO 1.21, Extended MAPI or Redemption code to set
them.
FlagDueBy + ReminderMinutesBeforeStart = ReminderTime
 
F

Foths Mylo

Dear Ken,

i will make a short summary, of the strange behaviour i found:

I want to set a reminder by using "getitemfromid" for to get the appointment
item.
The appointment is a simple appointment, not recuring.

i use the folowing code for the reminder:
objAppt.ReminderMinutesBeforeStart:=(60 * 23) + 59
objAppt.ReminderSet:= True;
objAppt.Save;

Then, i go to start->programs-> and i start the outlook application.
What happens, is this:
I can see the bell of the reminder, when i look at the appointment at the
calendar view.
If i open the appointment, by double clicking, the reminder check box is
checked, and the reminder "minutes before", is set as well. So everything
seems to be perfectly ok. Then i close the appointment, WITHOUT saving.

But finally, no matter how long i wait for, no reminder comes up.

It only comes up, if I SAVE the appointment first, and then close it.

Can you reproduce this case? Is it a matter of my outlook-exchange server
installtion, or is it a global issue? Is it a bug, or a "feature"?

If i understood well, you said that the lines of code i use, are not enough
for to set a reminder?

Does this happen, only when the variable "objAppt" comes from a
"getitemfromid" call?

Because if i use the same piece of code, when i have just created a new
apoitment item, then the reminder, is set corectly, and finally gets
displayed.

But, if i use this code with an appointment item instanciated by a call to
"getitemfromid", its not good enough.
In this case, for the reminder to work, i have to add as well, the call to
1) objAppt.disaply
---here goes the code that sets the properties-------
2) objAppt.close(olSave)

Then it works, but this is a problem to the end user, who will see something
poping up and eating his/her screen for a few seconds.

If i combine your notice of using CDO that exposes more properties, with my
observations, does this mean that displaying the item and closing it with
the "save" parameter, sets in the background the properties you mentioned?

And if this is the case, why there is no such probelm when i use a freshly
created apoitment? Why in that case the reminder is displayed correctly?

I'm sorry for the questions, i know you didn't make the outlook application,
but for the moment, you are my only hope for to find help and answers!

If you think, its no problem for you, i would also be greatfull for:
1) A code example of how to use CDO for to get an item that was created in a
previous oultook session, like the "getitemfromid" call i now use.
2) An example, for how to set the properties you mentioned, since its in a
GUID format and im not exactly sure what to do with it.
3) And finally, perhaps some info about oultook redemption? Is this a set of
new com objects in the market? A separete product? Do i have to redistribute
it, to install it, to buy it?

THANK YOU very much, indeed!
 
K

Ken Slovak - [MVP - Outlook]

Saving an item with a reminder will set certain properties. A new item
is different than an existing item, some properties aren't changed or
updated when the item is changed or aren't updated unless the item is
saved.

I avoid that entire mess by using CDO or Redemption code. Redemption
is a COM wrapper for Extended MAPI that has an object model and is
usable with languages such as VB. Extended MAPI is an API and can be
used only with C++ or Delphi. Redemption comes in personal and
redistributable versions. The redistributable version is what you need
if you are developing code that will be distributed to other people.
Redemption is located at www.dimastr.com/redemption. There are some
samples there of Redemption usage.

I get the appointment or other item as a CDO Message object. CDO
Appointments are only valid for items in the default Calendar folder.
I then use the Fields collection of the Message to add and set the
properties for ReminderTime, FlagDueBy and ReminderTimeBefore. These
would be named properties, so would be called using a form like:

Public Const CdoPropSetID4 = "0820060000000000C000000000000046"
Public Const FlagDueBy = "{" & CdoPropSetID4 & "}" & "0x8560"

oMessage.Fields(FlagDueBy) = #2/20/2004 10:00:00 AM#
'also set up ReminderTime and ReminderTimeBefore
oMessage.Update

You can see more examples of using CDO code at
www.cdolive.com/cdo5.htm and see various documented and undocumented
properties at www.cdolive.com/cdo10.htm

To get an Outlook item as a CDO item you use the EntryID and StoreID
of the Outlook item. So if oAppt is an Outlook appointment:

Dim oCDO As MAPI.Session
Dim oMessage As MAPI.Message
Dim strID As String
Dim strStoreID As String

Set oCDO = CreateObject("MAPI.Session")
oCDO.Logon "", "", False, False

strID = oAppt.EntryID
strStoreID = oAppt.Parent.StoreID

Set oMessage = oCDO.GetMessage(strID, strStoreID)
 
F

Foths Mylo

Ken,

your answers are very detailed and helpfull and i thank you very much.

I'll try to change my code for to see what happens first.

You see, i want this code to work for a comercial product of my company and
it will be a little dificult to re-write it for to use cdo everywhere. I'll
see if i can modify my code to work with your sugestions, something like
half outlook automation and half cdo usage.

i hope i can make it!

Thank you very much indeed.
 
K

Ken Slovak - [MVP - Outlook]

If you want to avoid the use of CDO 1.21 you can use Redemption code.
A combination of that and Outlook object model code will give you
pretty much everything you might need except for InfoStores and a few
other things.
 

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