Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting Outlook calendar items problem 1

Status
Not open for further replies.

StewartUK

Programmer
Joined
Feb 19, 2001
Messages
860
Location
GB
I've written a routine for our staff to book their holidays, part of which is to place an all-day appointment in their Outlook personal calendar.

There is also the facility to cancel holidays booked, part of which is to delete the entry in the personal calendar, using the Remove method.

It is this last step that doesn't quite work -
When you view the calendar within Outlook, the entry isn't there and using automation doesn't find the item either. However, if you go to book a meeting on that date, it shows up when you click the "Attendee availability" tab.

Here is the code for opening Outlook:
Code:
oOut = CREATEOBJECT("Outlook.application")
oMapi = oOut.GetNamespace("MAPI")
oPCal = oMapi.GetDefaultFolder(9)
oItems = oPCal.Items
This is my original code using the Remove method:
Code:
Itemcount = 0
FOR EACH oItem IN oItems
  ItemCount = ItemCount + 1
  IF oItem.Subject = [STEWART C-holiday] AND TTOD(oItem.Start) = ForDate
    oItems.Remove(ItemCount)
    EXIT
  ENDIF
ENDFOR
I tried the Delete method...
Code:
FOR EACH oItem IN oItems
   IF oitem.subject=[STEWART C-holiday] AND TTOD(oItem.Start) = ForDate
      oitem.Delete
      EXIT
   ENDIF
ENDFOR
...which worked perfectly when I stepped through the code in the Debugger. However when I let the code run, it fails on the Delete line saying "parameter is not optional"

Has anyone else come across this problem? Did you find a solution?

Thanks,

Stewart
 
Hi Stewart.

Has anyone else come across this problem? Did you find a solution?

I came across a similar problem using the move method of the item. I found that the solution was to store the result to a variable. So it may work if you modify your code like so:

Code:
FOR EACH oItem IN oItems
   IF oitem.subject=[STEWART C-holiday] AND TTOD(oItem.Start) = ForDate
      oCrap = oitem.Delete
      EXIT
   ENDIF
ENDFOR

Marcia G. Akins
 
Thanks Marcia,

That worked for me too (for some reason?!)

Stewart
 
Stewart

I believe I had also discovered that when I wrote FAq184-3894 (deleting an appointement).


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Ah yes thanks Mike.

Unfortunately the search facility wasn't working when I was trying to look for an answer to this.

Thanks,

Stewart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top