?
Solved

delete outlook calendar appointment from access

Posted on 2013-06-27
5
Medium Priority
?
622 Views
Last Modified: 2013-08-21
I have looked at a number of 'solutions' for this on here and other web sites, but none seem to work for me. I have code below to add an appointment from access (2007) to shared calendar. I need to be able to delete appointment from access. Any help would be appreciated.

Set outobj = CreateObject("outlook.application")
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objRecip = objNS.CreateRecipient(strName)

Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)

If Not objFolder Is Nothing Then
    Set objAppt = objFolder.Items.Add
    
    If objAppt Is Nothing Then
        Set objAppt = objApp.CreateItem(olAppointmentItem)
    End If
    
    
Else
    MsgBox "no access to the folder meaning it is not shared"
End If

 With objAppt
    .Start = Format(AppStartDate, "Short Date") & " " & Format(Appstarttime, "Short Time")
    .End = Format(AppEndDate, "Short Date") & " " & Format(Appendtime, "Short Time")
    .Location = AppLocation
    .Subject = AppSubject & " - " & AppBusiness
    Body = "Client: " & AppBusiness & vbCrLf & "No of Attendees " & AppNoOfDelegates
    Body = Body & vbCrLf & "Contact Name: " & ContactName
    Body = Body & vbCrLf & "Contact Tele: " & ContactNumber
    Body = Body & vbCrLf & "Contact Email: " & ContactEmail
   .Body = Body
            
    .Save

Open in new window



Above adds the appointment to the shared calendar, but how can I search for and delete appointment (using vba from access)
0
Comment
Question by:foxpc123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 39283849
Hi, foxpc123.

This should do it.  Pass this routine the name of the recipient and the subject of the appointment.  I'm assuming that the subject is unique (i.e. only one appointment with the subject).  If the subject isn't unique, then we'll need to make some changes to the code.

Sub DeleteAppointment(strName As String, strSubj As String)
    Const olFolderCalendar = 9
    Dim olkApp As Object, olkSes As Object, olkRcp As Object, olkFld As Object, olkApt As Object
    Set olkApp = CreateObject("Outlook.Application")
    Set olkSes = olkApp.GetNamespace("MAPI")
    olkSes.Logon olkApp.DefaultProfileName
    Set olkRcp = olkSes.CreateRecipient(strName)
    Set olkFld = olkSes.GetDefaultFolder(olFolderCalendar).Items
    Set olkApt = olkFld.Find("[Subject] = '" & strSubj & "'")
    If TypeName(olkApt) <> "Nothing" Then
        olkApt.Delete
    End If
    olkSes.Logoff
    Set olkApt = Nothing
    Set olkFld = Nothing
    Set olkRcp = Nothing
    Set olkSes = Nothing
    Set olkApt = Nothing
End Sub

Open in new window

0
 
LVL 3

Author Comment

by:foxpc123
ID: 39283908
Thanks BlueDevilFan. Will give it a try. However the Subject wasn't unique as it was a title of training course. However I can add a unique ID number to identify it.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39283915
You're welcome.

If the subject isn't unique, then the best we could do is delete all appointments with that subject or delete those within a certain date range.
0
 
LVL 3

Author Comment

by:foxpc123
ID: 39285928
BlueDevilFan,

Tried your suggestion, didn't seem to work. OlkApp was always set to nothing, even though strname was set to shared calendar name and strSubj was set to subject on appointment.

Is your solution for a shared calendar ?

Not sure about:
Const olFolderCalendar = 9

Open in new window

and
 Set olkFld = olkSes.GetDefaultFolder(olFolderCalendar).Items

Open in new window


Your code deletes the appointment from the default calendar and not the shared calendar (name stored in strName)
0
 
LVL 76

Accepted Solution

by:
David Lee earned 1500 total points
ID: 39310006
foxpc123,

Sorry to be so slow to get back to you.  

I don't know why olkApp would be set to Nothing.  What version of Outlook are you using?

You're right, I was getting the local calendar instead of a shared calendar.  I've corrected the code.  Please give this version a try.

Sub DeleteAppointment(strName As String, strSubj As String)
    Const olFolderCalendar = 9
    Dim olkApp As Object, olkSes As Object, olkRcp As Object, olkFld As Object, olkApt As Object
    Set olkApp = CreateObject("Outlook.Application")
    Set olkSes = olkApp.GetNamespace("MAPI")
    olkSes.Logon olkApp.DefaultProfileName
    Set olkRcp = olkSes.CreateRecipient(strName)
    Set olkFld = olkSes.GetSharedDefaultFolder(olkRcp, olFolderCalendar).Items
    Set olkApt = olkFld.Find("[Subject] = '" & strSubj & "'")
    If TypeName(olkApt) <> "Nothing" Then
        olkApt.Delete
    End If
    olkSes.Logoff
    Set olkApt = Nothing
    Set olkFld = Nothing
    Set olkRcp = Nothing
    Set olkSes = Nothing
    Set olkApt = Nothing
End Sub

Open in new window

0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

770 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