Programmatically change Duration

G

Guest

I have a number of appointments that got messed up from a third-party Outlook
to CRM synchronization product. The Duration of the meetings in question have
a negative value. I found this out by writing some code that traversed
through my Calendar's appointments.

When I try to use the Delete method against any of the problem items, I get
an error ("Run time error '-2147352567(80020009)' : Method '~' of object '~'
failed.") When I try to change the Duration property , I get the same type of
error.

I've written both a VB app and Outlook VBA to see if either one had better
access to the records in question. They both result in the same error.

Any ideas on how I can either modify the appointments or delete them would
be appreciated.

Thanks,
David
 
G

Guest

Sorry...here's the code I'm using:

Dim oOutlook As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim oAppt As AppointmentItem
Dim oItems As Items

Set oOutlook = New Outlook.Application
Set oNS = oOutlook.GetNamespace("MAPI")
Set oFldr = oNS.GetDefaultFolder(olFolderCalendar)

If oFldr Is Nothing Then GoTo Exit_For

Set oItems = oFldr.Items
Dim x As Integer
For x = 1 To oItems.Count
If x = 24 Or x = 25 Or x = 26 Or x = 27 Then
Debug.Print x & " - " & oItems(x).Subject
Debug.Print oItems(x).Start
Debug.Print oItems(x).Duration
oItems(x).Duration = 60
End If
Next

I know that items 24-27 are the suspect appointments because their durations
have a negative value in them. When I try to display the End property, I get
an runtime error as well.

Cheers,
David
 
G

Guest

Sorry...here's the code I'm using:

Dim oOutlook As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim oAppt As AppointmentItem
Dim oItems As Items

Set oOutlook = New Outlook.Application
Set oNS = oOutlook.GetNamespace("MAPI")
Set oFldr = oNS.GetDefaultFolder(olFolderCalendar)

If oFldr Is Nothing Then GoTo Exit_For

Set oItems = oFldr.Items
Dim x As Integer
For x = 1 To oItems.Count
If x = 24 Or x = 25 Or x = 26 Or x = 27 Then
Debug.Print x & " - " & oItems(x).Subject
Debug.Print oItems(x).Start
Debug.Print oItems(x).Duration
oItems(x).Duration = 60
End If
Next

I know that items 24-27 are the suspect appointments because their durations
have a negative value in them. When I try to display the End property, I get
an runtime error as well.

Cheers,
David
 
K

Ken Slovak - [MVP - Outlook]

Nothing odd in your code.

What I would do is assign an Object as you loop, an Object because some
other type of item might be in that folder. Then see if you get any errors
in the assignment and use Debug.Print for each one. If you get errors at
items 24 - 27 then the items are so corrupted that even code can't get at
them.
 

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