how to set user properties to a newly created appointment

Status
Not open for further replies.

savvaskef

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Here, I am trying to clone recurring appointments to a new calendar which has additional userproperties
but I get a

Run-time error '-2147417848(80010108)':
Automation error
The object invoked has disconnected from its clients

error when
1)setting a user property
2)set the recurrencepattern


code follows:
Code:
Private Sub clonecalwithproperties()
Dim primarycalendar As Outlook.Folder
Dim destinationcalendar As Outlook.Folder
Dim sourcecalendar As Outlook.Folder
Dim sourceitems As Outlook.Items
Dim appt As Outlook.AppointmentItem
'Does this have a OOO/WFH custom property set? This is set by a macro on the Meeting Request form
'If Appt.MeetingStatus = olMeeting And Not (Appt.ItemProperties.Item("OOORequest") Is Nothing) Then
Set primarycalendar = Outlook.Application.Session.GetDefaultFolder(olFolderCalendar)
Set sourcecalendar = primarycalendar.Folders("subfolder1")
Set destinationcalendar = primarycalendar.Folders("¸subfolder")
Set sourceitems = sourcecalendar.Items
         For Each appt In sourceitems
        
         Dim new_appt As AppointmentItem
         
        
        'Create appointment for sender's calendar
         Set new_appt = destinationcalendar.Items.Add
         With new_appt
             .Subject = appt.Subject
             .BusyStatus = appt.BusyStatus
             .ReminderSet = appt.ReminderSet
             .Start = appt.Start
             .End = appt.End
             .AllDayEvent = appt.AllDayEvent
             .Body = appt.Body
             .UserProperties("customercat") = appt.UserProperties("customercat")
             .UserProperties("productcat") = appt.UserProperties("productcat")
            
             .Save
            
         End With
        
         'If recurring meeting, duplicate recurrence pattern for new appointment
         Dim RPOrig As RecurrencePattern
         Dim RPNew As RecurrencePattern
         If appt.IsRecurring Then
             Set RPOrig = appt.GetRecurrencePattern
             Set RPNew = new_appt.GetRecurrencePattern
             RPNew = RPOrig
             new_appt.Save
            
            
         End If
        Next

            
         'End If
         
        'Release resources
         Set new_appt = Nothing


End Sub
(for my purposes the 1st occurrence of the error (on .userproperties("prop")) is of more importance because I do not know how to handle the exceptions and thus I will clone all appointments (even recurring ones) as one-off appointments.If you do have a way to do as such please comprehend
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
does it work if you don't copy the custom fields?

I think the problem is you need to add the custom field before setting the property
Dim objProp As Outlook.UserProperty
Set objProp = .UserProperties.Add("Friendly Field Name", olText, True)
objProp.Value = appt.UserProperties("customercat").value

you could try this first -
.UserProperties("customercat").value = appt.UserProperties("customercat").value
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Also, if nothing is changing, instead of
'Create appointment for sender's calendar
Set new_appt = destinationcalendar.Items.Add
With new_appt
..........

you could copy the apt and move it.
set new_appt = appt.copy
new_appt.Move destinationcalendar
 

savvaskef

New Member
Outlook version
Outlook 2010 32 bit
Email Account
thnx a lot diane,
Maybe my head is skipping properties of the outlook object model.What should I say?I am a bit spoiled by c# where types are explicit.thnx again
 

savvaskef

New Member
Outlook version
Outlook 2010 32 bit
Email Account
supposefully, if I wanted to copy recurrences (with any kind of rec.pattern and with all of their exceptions:some deleted, some with userproperties changed).is there a possible way to do such a thing?the error seems to be the same

(I do not want to copy or move appointments around since the form description is changed and they have the habbit to carry their own around to the new calendar even if its 9newly)assigned form template is set correct )
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This shows how to copy recurring events to individual appt. Copy Recurring Appointment Series to Appointments - that should get exceptions too, since it looks at the individual members of the collection. I'll have to look into copying the recurring pattern - i thought it worked, but either it doesn't or your code is missing a step (it looks good to me at 'first glance')
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
i posted this in comments on slipstick website - this is to create a new appointment, but you might try putting your code into the with or remove the save from within the with and put it at the end.
Dim pattern As Outlook.RecurrencePattern

With olAppt
'the other appt fields here

Set pattern = .GetRecurrencePattern
pattern.RecurrenceType = olRecursYearly
pattern.StartDate = .start
pattern.NoEndDate = True

.Save
end with
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
AFAIK, you can't copy the pattern, you need to copy each element of the pattern.

Code:
--snip--

         If appt.IsRecurring Then
         Dim RPOrig As RecurrencePattern
         Dim RPNew As RecurrencePattern
            Set RPOrig = appt.GetRecurrencePattern
            Set RPNew = .GetRecurrencePattern
          
RPNew.RecurrenceType = RPOrig.RecurrenceType
RPNew.PatternStartDate = RPOrig.PatternStartDate
RPNew.Occurrences = RPOrig.Occurrences
'RPNew.NoEndDate = RPOrig.NoEndDate
' for weekly appointments
RPNew.DayOfWeekMask = RPOrig.DayOfWeekMask

           
         End If
           
             .Save
           
         End With

you can copy the entire apt and keep the pattern intact - what I might do is copy it then edit the userprops as needed after it's copied, especially if they will different recurrencetypes.
RecurrencePattern.RecurrenceType Property (Outlook) has the valid fields for each pattern type.
 

savvaskef

New Member
Outlook version
Outlook 2010 32 bit
Email Account
thnx diane, the RecurrencePattern properties did the job for me. I just have to add a switch case statement for the different properties for each RecurrenceType. I do not know why I did not test that. I guess I was pessimistic by the different settings for each recurring appointment not knowing that recurrencetype defines which set of properties need to be set.
 

savvaskef

New Member
Outlook version
Outlook 2010 32 bit
Email Account
I thought it would be a good idea to post the select statement I implemented for fellow posters to see (in a nutshell you just forgot the interval property) but it is better for viewers to see the whole picture:

Set primarycalendar = Outlook.Application.Session.GetDefaultFolder(olFolderCalendar)
Set sourcecalendar = primarycalendar.Folders("sourcecalendar")
Set destinationcalendar = primarycalendar.Folders("destinationcalendar")
Set sourceitems = sourcecalendar.Items

sourceitems.IncludeRecurrences = False

For Each appt In sourceitems

'Create appointment for sender's calendar
Set new_appt = destinationcalendar.Items.Add
With new_appt
.Subject = appt.Subject
.BusyStatus = appt.BusyStatus
.ReminderSet = appt.ReminderSet
.ReminderMinutesBeforeStart = appt.ReminderMinutesBeforeStart
.Start = appt.Start
.End = appt.End
.AllDayEvent = appt.AllDayEvent
.Body = appt.Body
End With
Dim RPOrig As RecurrencePattern
Dim RPNew As RecurrencePattern
If appt.IsRecurring Then
Set RPOrig = appt.GetRecurrencePattern
Set RPNew = new_appt.GetRecurrencePattern
'can't RPNew = RPOrig
RPNew.RecurrenceType = RPOrig.RecurrenceType
RPNew.PatternStartDate = RPOrig.PatternStartDate
RPNew.Occurrences = RPOrig.Occurrences

If RPOrig.NoEndDate = True Then
RPNew.NoEndDate = True
Else
RPNew.NoEndDate = False
RPNew.Occurrences = RPOrig.Occurrences
End If


Select Case RPOrig.RecurrenceType
Case olRecursMonthly
RPNew.DayOfMonth = RPOrig.DayOfMonth
RPNew.Interval = RPOrig.Interval

Case olRecursMonthNth
RPNew.DayOfWeekMask = RPOrig.DayOfWeekMask
RPNew.Instance = RPOrig.Instance
RPNew.Interval = RPOrig.Interval



Case olRecursWeekly
RPNew.DayOfWeekMask = RPOrig.DayOfWeekMask
RPNew.Interval = RPOrig.Interval


Case olRecursYearly
RPNew.MonthOfYear = RPOrig.MonthOfYear
RPNew.Interval = RPOrig.Interval
RPNew.DayOfMonth = RPOrig.DayOfMonth
Case olRecursYearNth

RPNew.DayOfWeekMask = RPOrig.DayOfWeekMask
RPNew.Instance = RPOrig.Instance
RPNew.Interval = RPOrig.Interval
End Select


new_appt.Save
End If

Next
 

savvaskef

New Member
Outlook version
Outlook 2010 32 bit
Email Account
...but there's a but here:How can you handle exceptions?deleted,moved,updated? what can you do to copy these items?
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
N How to set automatically the default or user defined Quickstyle Templates by Answer in Outlook Using Outlook 1
M Exchange 2013 On premise set MessageRateLimit for User has no effect. Exchange Server Administration 0
A Block user to send emails to specific set of email ids Using Outlook 1
K why is a user getting email respond for invite respond that she didn't set up. Using Outlook 3
B Notice to user of appt. set by person with permission to edit (Outlook 2003) Using Outlook 7
D Is it possible to set up an email rule for a user based on alias address? Exchange Server Administration 3
W Outlook 2003 starts with new user set up page after 6 years of use Using Outlook 5
T I can't set up an Outlook email account on my wifes user account. Using Outlook 4
M Distribution Group: set a list of user in ManagedBy property Exchange Server Administration 3
bmtjedi Set objApp = Application Not Working in O365-32bit Using Outlook 1
F how do i set a reminder in onenote 2010 Using Outlook 8
glnz How set up new IMAP on Outlook-Office 365 and merge in pst from Outlook 2003 for same two email accounts? Using Outlook 5
ChrisK2 Send email to advertise@slipstick.com fails: "The group advertising isn't set up to receive messages from..." Using Outlook 3
S How to set up button in ribbon for individual Quick Steps Using Outlook 1
J Set Timer/Countdown on Emails? Outlook VBA and Custom Forms 3
Victor_50 Set all subfolders to not autoarchive Outlook VBA and Custom Forms 11
Z Script to set account? Using Outlook 0
4 Macro to set the category of Deleted Item? Outlook VBA and Custom Forms 2
J What is the best EntryID format to set on MS Access table Outlook VBA and Custom Forms 3
e_a_g_l_e_p_i Can you set reminder to specific times? Using Outlook 7
CWM030 I do not see a way to set the personal archive folder Exchange Server Administration 2
witzker Macro to set contact reminder to next day 9:00 Outlook VBA and Custom Forms 45
O Set columns for all (sub)folders Using Outlook 8
S Appointment-Cannot set Categories because ConversationID is not set Outlook VBA and Custom Forms 1
Fozzie Bear Correct Method to set up Outlook.com accounts as Exchange Using Outlook.com accounts in Outlook 7
e_a_g_l_e_p_i How to set fonts for emails in all folders in Outlook Using Outlook 1
F Set (flagged) reminder for next business day Using Outlook 4
L how to set downloaded cached emails Using Outlook 5
J Object Variable or With Block Not Set Error in Outlook 2016 and not Outlook 2013 Outlook VBA and Custom Forms 3
S set a flag task date as the next weekday Outlook VBA and Custom Forms 4
C Set reminder / appointment by right clicking email Using Outlook 1
Diane Poremsky Set Another Data File as Default When Using an Exchange Account New Slipstick.com Articles 0
R Macro to copy email to excel - Runtime Error 91 Object Variable Not Set Outlook VBA and Custom Forms 11
L set task reminder date to same as start date (without affecting due date) Using Outlook 0
C Outlook VBA to set current account Outlook VBA and Custom Forms 1
Diane Poremsky Add Attachments and Set Email Fields During a Mail Merge New Slipstick.com Articles 0
O How to set subject line in replies using VBA Outlook VBA and Custom Forms 1
A Custom form not showing when recurrence is set for a meeting Using Outlook 0
D Outlook 2007 e-mail header- How to set font & font size in received message headers ? Using Outlook 2
Diane Poremsky Exchange account set-up missing in Outlook 2016 New Slipstick.com Articles 0
M To set the storage folder for an outgoing Outlook message Outlook VBA and Custom Forms 8
E Meeting reminders are set for the recipient Exchange Server Administration 9
M Help! Can't set up IMAP for gmail Using Outlook 2
P Last Change attribute set after viewing a public folder contact Exchange Server Administration 0
S Multiple Gmail account set up in Outlook 365 Using Outlook 1
Diane Poremsky Add attachments and set email fields during a mail merge to email New Slipstick.com Articles 0
D Script to parse email and set a task Outlook VBA and Custom Forms 1
K Outlook 2010 - Set the category based on category of other emails in same conversatio Using Outlook 20
A iCloud add-on for Outlook: Reminder for new appointment is set to 'None' by default. How to change? Using Outlook 6
A set onedrive calendar as default in Outlook Using Outlook.com accounts in Outlook 4
Similar threads


















































Top