Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Update Outlook Appointment

Posted on 2004-08-20
1
Medium Priority
?
561 Views
Last Modified: 2013-12-25
Hi all

I am using the code below to search for all appointments after a certain date. Then I want to update the Categories of the appointments.

The problem is it adds a new appointment instead of Updating an existing one.
Any help highly appreciated.



 Dim objOutlook As Outlook.Application
        Dim objAppt As Outlook.AppointmentItem
        Dim objRecurPattern As Outlook.RecurrencePattern
  Set objOutlook = CreateObject("Outlook.Application")
        Set objAppt = objOutlook.CreateItem(olAppointmentItem)
       
 
 Dim ol As Object
      Dim olns As Object
      Dim objFolder As Object
      Dim objAllAppoint As Object
      Dim Appoint As Object
      ' Set the application object
      Set ol = New Outlook.Application
      ' Set the namespace object
      Set olns = ol.GetNamespace("MAPI")
      ' Set the default Calendar folder
      Set objFolder = olns.GetDefaultFolder(olFolderCalendar)
     
      Set objAllAppoint  = objFolder.Items
      ' Loop through each Appointment
     
      Dim st As String
      Dim dt As Date
      For Each Appoint  In objAllAppoint
     st = Format(Appoint.Start, "dd-mm-yyyy")
     dt = "01-01-2004"
     
         If st > dt Then
       
       
       objAppt.Categories = "Processed"
       
     
       objAppt.Save
     
  End if
Next
   

End Sub
0
Comment
Question by:Shezad Ahmed
1 Comment
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 11857538
Try this.  It works in my environment.

Private Sub Command1_Click()
    Dim objOutlook As New Outlook.Application
    Dim objNameSpace As Outlook.NameSpace
    Dim objFolder As Outlook.MAPIFolder
    Dim objAppt As Outlook.AppointmentItem
    Dim datStarting As Date
    Dim intCount As Integer
 
    ' Set the namespace object
    Set objNameSpace = objOutlook.GetNamespace("MAPI")
   
    ' Login to a profile
    objNameSpace.Logon "MyProfileName", "MyPassword"
   
    ' Set the default Calendar folder
    Set objFolder = objNameSpace.GetDefaultFolder(olFolderCalendar)
   
    ' Set the starting date (be sure to include a time too)
    datStarting = #8/19/2004 11:59:59 PM#
   
    ' Loop through the appointments backwards
    For intCount = objFolder.Items.Count To 1 Step -1
        ' Get the appointment item
        Set objAppt = objFolder.Items(intCount)
        ' Is the
        If objAppt.Start > datStarting Then
            ' Are other categories already present
            If Len(objAppt.Categories) > 0 Then
                ' Append the new category to the existing list of cats
                objAppt.Categories = objAppt.Categories & ",Processed"
            Else
                ' Set the category
                objAppt.Categories = "Processed"
            End If
            ' Save the appointment
            objAppt.Save
        End If
    Next
    ' Log out
    objNameSpace.Logoff
    ' Dispose of the objects to avoid memory leaks
    Set objAppt = Nothing
    Set objFolder = Nothing
    Set objNameSpace = Nothing
    Set objOutlook = Nothing
End Sub
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question