Solved

Update Outlook Appointment

Posted on 2004-08-20
1
553 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 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.net 2008 2 56
Question about INSTR  - need to extract data MS ACCESS query 6 54
How does CurrentUser work? 10 31
clicking a shape in a frame array vb6 3 40
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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now