J
Juan J
Hi
I have some code that copies an appointment from one calendar to another (a
different PST ) and it works fine when you create that appointment. What I
need to do now is to reflect changes in the original appointment into the
second one, but I need to make sure that no matter what is changed in the
appointment, the "find" method still can find the copy of the appointment.
For example I can´t do the search based in date, subject or status since I
can´t trap the event before the change has taken place so the "find" method
would fail to find the record in the second calendar. To do this I used the
billinginformation field to put some data that would identify both the
original and the copied record. The problem is that the code seems to write
the information in the field of both appointments but when I retrieve the
field of the changed appointment it is shown in blank (no data in it) so the
find method fails. Anybody knows why the value is not kept in the field?
Thanks.
Attached you will find the coding
Dim myOlApp As New Outlook.Application
Public WithEvents CalendarItems As Outlook.Items
Public Sub Initialize_handler()
Set CalendarItems =
myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar).Items
End Sub
Private Sub Application_Startup()
Initialize_handler
End Sub
Private Sub CalendarItems_Itemadd(ByVal Item As Object)
Dim mycopiedappt As Outlook.AppointmentItem
Dim PalmFolder As Outlook.Folders
Dim OPalmFolder As Outlook.MAPIFolder
Item.BillingInformation = Item.LastModificationTime
MsgBox Item.BillingInformation
Set OPalmFolder =
myOlApp.GetNamespace("MAPI").Folders.Item("PALM_Respaldo")
Set PalmFolder = OPalmFolder.Folders
Set OPalmFolder = PalmFolder.Item("Calendar(PALM)")
Set mycopiedappt = Item.Copy
MsgBox mycopiedappt.BillingInformation
mycopiedappt.Move OPalmFolder
End Sub
Private Sub CalendarItems_Itemchange(ByVal Item As Object)
Dim mychgappt As Outlook.AppointmentItem
Dim OCalItem As Outlook.AppointmentItem
Dim PalmFolder As Outlook.Folders
Dim OPalmFolder As Outlook.MAPIFolder
Dim OStr As String
Set OPalmFolder =
myOlApp.GetNamespace("MAPI").Folders.Item("PALM_Respaldo")
Set PalmFolder = OPalmFolder.Folders
Set OPalmFolder = PalmFolder.Item("Calendar(PALM)")
OStr = "[BillingInformation]=" & Item.BillingInformation
'(here the item.billinginformation data returns blank or ""
Set OCalItem = OPalmFolder.Items.Find("[BillingInformation]=" &
Item.BillingInformation)
If TypeName(OCalItem) <> "Nothing" Then
OCalItem.Delete
Set mychgappt = Item.Copy
mychgappt.Move OPalmFolder
Else
MsgBox "Can´t find corresponding appointment"
End If
End Sub
I have some code that copies an appointment from one calendar to another (a
different PST ) and it works fine when you create that appointment. What I
need to do now is to reflect changes in the original appointment into the
second one, but I need to make sure that no matter what is changed in the
appointment, the "find" method still can find the copy of the appointment.
For example I can´t do the search based in date, subject or status since I
can´t trap the event before the change has taken place so the "find" method
would fail to find the record in the second calendar. To do this I used the
billinginformation field to put some data that would identify both the
original and the copied record. The problem is that the code seems to write
the information in the field of both appointments but when I retrieve the
field of the changed appointment it is shown in blank (no data in it) so the
find method fails. Anybody knows why the value is not kept in the field?
Thanks.
Attached you will find the coding
Dim myOlApp As New Outlook.Application
Public WithEvents CalendarItems As Outlook.Items
Public Sub Initialize_handler()
Set CalendarItems =
myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar).Items
End Sub
Private Sub Application_Startup()
Initialize_handler
End Sub
Private Sub CalendarItems_Itemadd(ByVal Item As Object)
Dim mycopiedappt As Outlook.AppointmentItem
Dim PalmFolder As Outlook.Folders
Dim OPalmFolder As Outlook.MAPIFolder
Item.BillingInformation = Item.LastModificationTime
MsgBox Item.BillingInformation
Set OPalmFolder =
myOlApp.GetNamespace("MAPI").Folders.Item("PALM_Respaldo")
Set PalmFolder = OPalmFolder.Folders
Set OPalmFolder = PalmFolder.Item("Calendar(PALM)")
Set mycopiedappt = Item.Copy
MsgBox mycopiedappt.BillingInformation
mycopiedappt.Move OPalmFolder
End Sub
Private Sub CalendarItems_Itemchange(ByVal Item As Object)
Dim mychgappt As Outlook.AppointmentItem
Dim OCalItem As Outlook.AppointmentItem
Dim PalmFolder As Outlook.Folders
Dim OPalmFolder As Outlook.MAPIFolder
Dim OStr As String
Set OPalmFolder =
myOlApp.GetNamespace("MAPI").Folders.Item("PALM_Respaldo")
Set PalmFolder = OPalmFolder.Folders
Set OPalmFolder = PalmFolder.Item("Calendar(PALM)")
OStr = "[BillingInformation]=" & Item.BillingInformation
'(here the item.billinginformation data returns blank or ""
Set OCalItem = OPalmFolder.Items.Find("[BillingInformation]=" &
Item.BillingInformation)
If TypeName(OCalItem) <> "Nothing" Then
OCalItem.Delete
Set mychgappt = Item.Copy
mychgappt.Move OPalmFolder
Else
MsgBox "Can´t find corresponding appointment"
End If
End Sub