Deleting an Outlook Appointment from Access VBA (1 Viewer)

cyd44

Registered User.
Local time
Today, 17:11
Joined
Oct 30, 2011
Messages
85
Could anyone help as I am pulling my hair out trying to figure out the object variables required to find and delete an Outlook appointment from Access. I understand the principles but cannot get anything to compile. Is there a simple set of generic object varialble that will open up my outlook calendar on my laptop and delete an appointment based upon Subject, Start & location.
 

NigelShaw

Registered User.
Local time
Today, 17:11
Joined
Jan 11, 2008
Messages
1,573
Could anyone help as I am pulling my hair out trying to figure out the object variables required to find and delete an Outlook appointment from Access. I understand the principles but cannot get anything to compile. Is there a simple set of generic object varialble that will open up my outlook calendar on my laptop and delete an appointment based upon Subject, Start & location.

Hi

You can delete an appointment based on any of those things and you can also delete ppointments in single or series.

If you like, I might have a db that demonstrates. Let me know if it's of interest and I'll have a look for it.

Cheers


Nidge
 

cyd44

Registered User.
Local time
Today, 17:11
Joined
Oct 30, 2011
Messages
85
Hi

You can delete an appointment based on any of those things and you can also delete ppointments in single or series.

If you like, I might have a db that demonstrates. Let me know if it's of interest and I'll have a look for it.

Cheers


Nidge
Hi Nigel

Many thanks for the infi. I would be delighted if you could send me the code. Wher I am struggling is with the object declarations and am getting myself tied up in nots ususing strFilter to connect. I have obviously got the object syntax wrong as I keep getting compile errors
Cyd
 

cyd44

Registered User.
Local time
Today, 17:11
Joined
Oct 30, 2011
Messages
85
Could anyone else please offer advice.I think that perhaps Nigel could not find what he was looking for but I am still desparate to understand the logic for finding an appointment to delete it using access.

Would really appreciate some help on this.

Many thanks
 

NigelShaw

Registered User.
Local time
Today, 17:11
Joined
Jan 11, 2008
Messages
1,573
Could anyone else please offer advice.I think that perhaps Nigel could not find what he was looking for but I am still desparate to understand the logic for finding an appointment to delete it using access.

Would really appreciate some help on this.

Many thanks

Sorry

Not managed to get to my pc. I'll post it tonight.

Cheers

Nigel
 

cyd44

Registered User.
Local time
Today, 17:11
Joined
Oct 30, 2011
Messages
85
May thanks Nigel, I thought that maybe you had not been able to find it,Please dont think I was complaining, just thought you had lost it and it wasnt worth getting back to me with a negative.
look forward to receiving your recomedation.

Many thanks
 

NigelShaw

Registered User.
Local time
Today, 17:11
Joined
Jan 11, 2008
Messages
1,573
May thanks Nigel, I thought that maybe you had not been able to find it,Please dont think I was complaining, just thought you had lost it and it wasnt worth getting back to me with a negative.
look forward to receiving your recomedation.

Many thanks

Hi Cyd

here it is. to use,

change your settings in GetAppDetails
call AddAppClosedOutlk to add appointment (this will add even if outlook is closed)
call DeleteAppBySubject to delete the appointment

there are other functions and ways of adding / deleting appointments. You can also set recurrences, and importance.

Let me know how you get on and i'll help where i can.

btw,

this is in accdb format. is that ok?

You need these references too



Cheers

Nigel
 

Attachments

  • OutlookApps.accdb
    544 KB · Views: 225
  • appRefs.JPG
    appRefs.JPG
    50.4 KB · Views: 1,182

cyd44

Registered User.
Local time
Today, 17:11
Joined
Oct 30, 2011
Messages
85
Hi Nigel,

Many thanks for this. I will need to realy look at it before attempting to use it as it is way beyond my current capability with access.

Please find the code I have currently developed which does not give any error but always comes up with 0 appointments deleted?

Would appreciate your advice on it.
 

Attachments

  • Code.doc
    25 KB · Views: 227

cyd44

Registered User.
Local time
Today, 17:11
Joined
Oct 30, 2011
Messages
85
Nigel
Have just worked out how to send you my code better, Please ignore the attachment on my last.

here is my code
Code:
' The Following variable assignments will pick-up the old booking data prior to the change in order
    ' to find and delete an Outlook booking. Variables have been caputured by the Sub Form_Current()procedure
    ' and declared Public in the basMyEmpID Standard Code Module.
    
            Dim goldLocation As String
            Dim goldStart As Date
            Dim goldDate As Date
            Dim goldName As String
 
            goldLocation = basMyEmpID.gstroldLocation 'golbal str variable
            goldStart = basMyEmpID.gdteoldStart 'global time varaible medium time
            goldDate = basMyEmpID.gdteoldDate   'global date variable short date
            goldName = basMyEmpID.gstroldName   'global strt variable
            
        
            
' Connection to Outlook Variables
 
                
                Dim objOlook As Outlook.Application
                Dim objNamespace As Outlook.NameSpace
                Dim objFolder As Outlook.MAPIFolder
                Dim objAppointment As Outlook.AppointmentItem
                Dim objOAppt As Outlook.Items
                Dim lngDeletedAppointements As Long
                Dim strSubject As String
                Dim strLocation As String
                Dim dteStartDate As Date
  
'******************************** Set Criteria for DELETION here ********************************
                strSubject = goldName
                strLocation = goldLocation
                dteStartDate = goldDate + goldStart
                
                
            
                MsgBox (strSubject & strLocation)
'************************************************************************************************
  
              Set objOlook = CreateObject("Outlook.Application")
             Set objNamespace = objOlook.GetNamespace("MAPI")
             Set objFolder = objNamespace.GetDefaultFolder(olFolderCalendar)
             
             For Each objAppointment In objFolder.Items
             If objAppointment.Subject = goldName And objAppointment.Location = goldLocation And _
             objAppointment.Start > dteStartDate Then
             objAppointment.Delete
             lngDeletedAppointements = lngDeletedAppointements + 1
            End If
            Next
            
MsgBox lngDeletedAppointements & " appointment(s) DELETED.", vbInformation, "DETETE Appointments"

                
              GoTo Ender
              Exit Sub
 

NigelShaw

Registered User.
Local time
Today, 17:11
Joined
Jan 11, 2008
Messages
1,573
Hi,

you could try this-
Code:
Private Sub DeleteAppointmentItemBySubject(strAppSubject As String)
    '   Use this method ONLY if the subject of the
    '   Appointment Item is known and is UNIQUE.

    Set objOlook = CreateObject("Outlook.Application")
    Set objNamespace = objOlook.GetNamespace("MAPI")
    objNamespace.Logon , , False, False
    Set objFolder = objNamespace.GetDefaultFolder(olFolderCalendar)
    On Error Resume Next
    Set objAPPT = objFolder.Items(strAppSubject)
    If Err.Number <> 0 Then GoTo CannotFindObject
    mobjAPPT.Delete
    
MsgBox lngDeletedAppointements & " appointment(s) DELETED.", vbInformation, "DETETE Appointments"

Bye:
    Set objAPPT = Nothing
    Set objFolder = Nothing
    Set objNamespace = Nothing
    Set objOlook = Nothing
    Exit Sub
CannotFindObject:
    MsgBox "Cannot find Appointment Item to delete.", _
        vbOKOnly, "Information"
    GoTo Bye
End Sub
call it with this-
Code:
Call DeleteAppointmentItemBySubject(strAppSubject)
where strAppSubject is the appointment subject so lets say its called CydsTest, you would call-
Code:
Call DeleteAppointmentItemBySubject("CydsTest")
or
Code:
Dim strAppSubject As String
strAppSubject = "CydsTest"
Call DeleteAppointmentItemBySubject(strAppSubject)

let me know if that works



cheers

Nigel
 

cyd44

Registered User.
Local time
Today, 17:11
Joined
Oct 30, 2011
Messages
85
Hi Nigel,

Am working with your suggestion for a later version as I managed to get my code working ok AT LAST! I was really struggling with the declaration aspect and found that there were no examples avialable anywhere.

I fully appreciate your help on this and for the code, looking at yours helped me fathom out what was wrong with mine.

Your code looks much tighter and I will use it but am up against a tight deadline on this project so I will run with mine for the time being.

Once agian my friend, many many thanks for your help.
 

Users who are viewing this thread

Top Bottom