How to set field value by RDO?

  • Thread starter Thread starter Peter Marchert
  • Start date Start date
P

Peter Marchert

Hello,

I found code on Dmitrys Homepage to read field values by RDO but not
how to write new values to a field. The code should set the color of
appointment labels:

Sub SetLabelColor()

Dim objRDOSession As Object
Dim objRDOMail As Object
Dim objAppointment As Outlook.AppointmentItem

Set objAppointment = Outlook.ActiveExplorer.Selection(1)
Set objRDOSession = CreateObject("Redemption.RDOSession")

objRDOSession.Logon
Set objRDOMail =
objRDOSession.GetMessageFromID(objAppointment.EntryID,
objAppointment.Parent.StoreID)
MsgBox objRDOMail.Fields("http://schemas.microsoft.com/mapi/id/
{00062002-0000-0000-C000-000000000046}/82140003")

End Sub

Thanks for hints.

Peter
 
objRDOMail.Fields("http://schemas.microsoft.com/mapi/id/{00062002-0000-0000-C000-000000000046}/82140003")
= NewValue
See http://www.dimastr.com/redemption/rdo/MAPIProp.htm#properties

Also note that if you are already using OOM, there is no reason to call
RDOSession.Logon.
Replace it with
objRDOSession.MAPIOBJECT = Outlook.Session.MAPIOBJECT

Also keep in mind that RDO is designed to be used standalone (pretty much
like CDO 1.21), even though you can of course use it along with OOM.
In your case a better solution would be the SafeAppointmentItem object:

Set objAppointment = Outlook.ActiveExplorer.Selection(1)
set sItem = CreateObject("Redemption.SafeAppointmentItem")
sItem.Item = objAppointment
PR_COLOR = sItem.GetIDsFromNames("{00062002-0000-0000-C000-000000000046}",
&H82140003) OR 3 'PT_LONG
sItem.Fields(PR_COLOR) = NewValue



Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Thanks a lot for your reply, Dmitry.

With the RDO code it now works, but I want to use the safe item to
change the color. There must be a problem with the code:

Sub SetLabelColor()

Set objAppointment = Outlook.ActiveExplorer.Selection(1)
Set sItem = CreateObject("Redemption.SafeAppointmentItem")
sItem.Item = objAppointment
PR_COLOR = sItem.GetIDsFromNames("{00062002-0000-0000-
C000-000000000046}", &H82140003) Or 3 'PT_LONG
sItem.Fields(PR_COLOR) = 9

End Sub

because he change nothing. I watched with Outlook Spy when running the
code and nothing happens. If I run the code again and set a break
point to the line "sItem.Fields(PR_COLOR) = 9" the field already has
the new value.

Also these codes change nothing:

Sub SetReminderMinutesBeforeStart()

Set objAppointment = Outlook.ActiveExplorer.Selection(1)
Set sItem = CreateObject("Redemption.SafeAppointmentItem")
sItem.Item = objAppointment
PR_MINUTES = sItem.GetIDsFromNames("{00062002-0000-0000-
C000-000000000046}", &H80220003) Or 3 'PT_LONG
sItem.Fields(PR_MINUTES) = 20

End Sub

Sub UnSetReminder()

Set objAppointment = Outlook.ActiveExplorer.Selection(1)
Set sItem = CreateObject("Redemption.SafeAppointmentItem")
sItem.Item = objAppointment
PR_REMINDERSET = sItem.GetIDsFromNames("{00062002-0000-0000-
C000-000000000046}", &H8002) Or 11 'PT_BOOLEAN
sItem.Fields(PR_REMINDERSET) = False
sItem.Save

End Sub

I have no idea and need help again.
Peter
 
Peter,
does it work after you go to a different folder and then come back and
reopen the appointment?
You migth also want to save the appointment, but you need to trick Outlook
into thinking that something has changed first:

sItem.Fields(PR_COLOR) = 9
objAppointment.Subject = objAppointment.Subject
objAppointment.Save

As for the reminder, you can set these properties using the native OOM
object.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Sorry, no different. I changed the code to:

Sub SetLabelColor()

Set objAppointment = Outlook.ActiveExplorer.Selection(1)
Set sItem = CreateObject("Redemption.SafeAppointmentItem")
sItem.Item = objAppointment
PR_COLOR = sItem.GetIDsFromNames("{00062002-0000-0000-
C000-000000000046}", &H82140003) Or 3 'PT_LONG
sItem.Fields(PR_COLOR) = 9
objAppointment.Subject = objAppointment.Subject
objAppointment.Save

End Sub

and changed the folder and reopend the item. Nohting changed. I tried
it also in a virtual machine. Does this code work on your machine?

Peter
 
Back
Top