Open a single Outlook Calendar Appointment, Edit it or Delete it

Chrism2

Registered User.
Local time
Today, 20:43
Joined
Jun 2, 2006
Messages
161
Hi there,

Elsewhere on this forum there is an example of how to add a calendar item to Outlook via Access. There is also an example of how to pull out a single appointment, edit it or delete it.

I'm storing a unique ID in the [mileage] field in the appointment - and if necessary, I can store the full appointment info in a table.

I can cope with adding the Outlook Item with the following code:

Code:
Private Sub cmdCreateAppointment_Click()

            Dim outobj As Outlook.Application
            Dim outappt As Outlook.AppointmentItem
            Set outobj = CreateObject("outlook.application")
            Set outappt = outobj.CreateItem(olAppointmentItem)
            With outappt
               .Start = Me.EventStart & " " & Me.time
               .Duration = Me.Duration
               .Subject = Me.Subject
               .Mileage = Me.uniqueID
         
               .Save
            End With

         Set outobj = Nothing

         DoCmd.RunCommand acCmdSaveRecord
         MsgBox "Appointment Added!"
      Exit Sub


End Sub

But recalling the appointment and updating it or deleting it is really confusing me. I'm struggling to find any useful resources covering Outlook.Application and it's use so I'm hoping for some pointers here.

Can someone help?

Thanks!
 
You said you had an example of how to do it; what does that code look like? What problem are you having with it? The only method I know of involves looping through the calendar folder and looking for the appropriate item (in your case, by matching the unique ID).
 
Interesting; I hadn't thought to use the Filter. I may test that later, as it would likely be more efficient that what I did. Presuming it works, it's hard to say why it isn't working for you without seeing your code. As a guess, if you're unique ID is text, this might work:

sFilter = "[Mileage] = '" & Me.uniqueID& "'"

If that doesn't help, post your code and let us know what "isn't working for me" means exactly (error, incorrect result, etc).
 
Well, here's the code I'm trying to use - two basic forms and a module - I'm not storing the data (I don't want to yet) - I just want to be able to add and then amend as necessary.

frmOpenAppointment is the one not working. All I'm looking for it to do is bring back the subject according to the UniqueID. (Set manually in frmCreateAppointment). In a live db, I'd have UniqueID hidden from view and automatic - all the data stored in a table...

Any help would be lovely...

Ta
 

Attachments

I have cut this out for you so it might not be 100% correct but here is how to find an appointment in a SHARED folder. You would have to change this for your own folder.


Code:
'objApp is the Outlook Application object


Set objNS = objApp.GetNamespace("MAPI")

Set objRecip = objNS.CreateRecipient(strName)

'my example uses a shared folder but you can change it to your defaul
Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
'use your ID here
sFilter = "[Mileage] = " & app_CalendarID & ""


If Not objFolder Is Nothing Then

    Set objAppt = objFolder.Items.Find(sFilter)

    If objAppt Is Nothing Then
        MsgBox "Could not find appointment"
    Else
        With objAppt
            
            Do whatever you want To the appointment
        End With
    End If
End If

edit: now I see I am also on the other thread as well. Ok I will have a look at your code as well.
 
Sorry but I do not have Access 2007 so cannot look at it right now. Maybe over the weekend I will.
 
Well,

This works:

Edit: It works with *early* referencing, so Microsoft Outlook #.# Object Library needs to be added into references.

Code:
Option Compare Database



Private Sub Find_Record_Click()

Dim objApp As Outlook.Application
Dim objAppt As Object
   
Set objApp = New Outlook.Application
Set objNS = objApp.GetNamespace("MAPI")

Set objRecip = objNS.CreateRecipient(strName)
Set objFolder = objNS.GetDefaultFolder(olFolderCalendar)


Dim sfilter As String
sfilter = "[Mileage] = " & Me.uniqueID & ""


Set objAppt = objFolder.Items.Find(sfilter)  ' olAppointmentItem


With objAppt

               Me.subject = .subject
               Me.start = .start
               Me.duration = .duration
               

            .Save
      End With
       ' Release the Outlook object variables.
       Set olappt = Nothing
       Set olapp = Nothing    ' Set chkAddedToOutlook to checked
      ' Me.chkAddedtoOutlook = True

       ' Save the Current Record because we checked chkAddedToOutlook
       If Me.Dirty Then
           Me.Dirty = False
      End If



End Sub

It would be beneficial to understand the method using late referencing - most of the people I'm dealing with don't use the same versions of Outlook / Office - which invariably causes problems on start up. My DB's are not really big enough for late referencing to cause a problematic performance hit.

Thanks all!
 
I am not an expert at that kind of stuff but I will get you started.

First just change everything to an object instead of Outlook.Application etc.

I think also you need to use the getobject and createobject functions to get your outlook object.

basically you start with a getobject in case outlook is already running and then if there is an error 429 you use a createobject.

There are thousands of examples of this.

The only thing I can think of that will then cause you problems are

1. the computer has no outlook at all
2. the older outlook does not support one of the methods, properties or functions that you use.
 
Hi,

the crux of your problem I believe is retrieving the entryid (a huge UID for Outlook appointments.)
with your appointment object you can retrieve as follows.

Code:
myID = olApt.EntryID

Ok, now you have your EntryID you can then subsequently re-retrieve the appointment object like such...

Code:
Dim olApp as Outlook.Application
Dim olNs as Namespace
Dim olApt as Outlook.AppointmentItem

set olApp = CreateObject("Outlook.Application")
set olNs = olApp.GetNamespace("MAPI")
Set olApt = olNs.GetItemFromID(myID)


BTW: I cant take credit for the above. Most of what Ive learnt is from Sue Mosher through my own Googling....
 
the crux of your problem I believe is retrieving the entryid (a huge UID for Outlook appointments.)
with your appointment object you can retrieve as follows.
Yes Outlook does have an ID for most things including folders and items. The only problem is that if a user moves an item around then the ID changes. This is why people use either a property that exists or makes up their own property and adds a unique ID to it.

BTW: I cant take credit for the above. Most of what Ive learnt is from Sue Mosher through my own Googling....

I agree. I too have learnt alot from her books and website.
 
Hi,
I'm trying to export an appointment from Access to Outlook and then have the ability to delete it from Outlook. The following code works to create the appointment, but it gives the message "appointment not found" when attempting to delete it. I'm using the primary key for the appointment event in the Access table to save as "mileage" in the appointment and then using this to search for the appointment in order to delete it.

Any help would be appreciated!!

Here's my code:
Code:
Private Sub cmdAddToOutlook_Click()
 
    'Save record first to be sure required fields are filled.
    DoCmd.RunCommand acCmdSaveRecord
 
    'Exit the procedure if appointment has been added to Outlook
    If Me!AddedToOutlook = True Then
        MsgBox "This appointment is already added to Microsoft Outlook", vbInformation
        Exit Sub
    Else
        'Add a new appointment
        Dim oApp As Object
        Dim oCalendar As Outlook.MAPIFolder
        Dim oNameSpace As Outlook.NameSpace
        Dim oDummy As Outlook.MailItem
        Dim oAppt As Outlook.AppointmentItem
        Dim oAcct As Outlook.Recipient
        Dim ApptNotes As String
        'Dim strName As String
        Dim calName As String
        On Error Resume Next
 
        calName = ""
        Set oApp = CreateObject("Outlook.Application.12")
        Set oNameSpace = oApp.GetNamespace("Mapi")
        Set oAcct = oNameSpace.CreateRecipient(calName)
        Set oCalendar = oNameSpace.GetSharedDefaultFolder(oAcct, olFolderCalendar)
        Set oAppt = oCalendar.Items.Add(olAppointmentItem)
 
        'Save Appointment
        With oAppt
            .Subject = Me!ReservingOrganization & ": " & Me!StartTime & " - " & Me!EndTime
             .Start = Format(Me.StartDate, "Short Date") & " " & Format(Me.StartTime, "Short Time")
            .End = Format(Me.EndDate, "Short Date") & " " & Format(Me.EndTime, "Short Time")
            .ReminderSet = False
            .Mileage = Me!RoomRequestID.Value
            .Save
            .Close (olSave)
        End With
        Me!AddedToOutlook = True
        MsgBox "Appointment Added!", vbInformation
    End If
    'Release the Outlook object variable
    Set oCalendar = Nothing
    Set oNameSpace = Nothing
    Set oApp = Nothing
 
Err_Exit:
    Set oCalendar = Nothing
    Set oNameSpace = Nothing
    Set oApp = Nothing
    Exit Sub
 
Err_cmdAddToOutlook_Click:
    MsgBox Err.Description
    MsgBox Err.Number
 
End Sub
 
Private Sub cmdDeleteFromOutlook_Click()
    'Find Appointment in Outlook and delete
    Dim olApp As Outlook.Application
    Dim objAppointment As Outlook.AppointmentItem
    Dim objAppointments As Outlook.MAPIFolder
    Dim objNameSpace As Outlook.NameSpace
    Dim objProperty As Outlook.UserProperty
    Dim OutlookStartTime, OutlookEndTime As Date
    Dim sFilter As Variant
 
    OutlookStartTime = CDate(Me!StartDate & " " & Me!StartTime)
    OutlookEndTime = CDate(Me!EndDate & " " & Me!EndTime)
 
    Set olApp = CreateObject("Outlook.Application")
    Set objNameSpace = olApp.GetNamespace("MAPI")
    Set objAppointments = objNameSpace.GetDefaultFolder(olFolderCalendar)
 
    sFilter = "[Mileage] = " & Me!RoomRequestID.Value & ""
    Set objAppointment = objAppointments.Items.Find(sFilter)
 
    If Not TypeName(objAppointment) = "Nothing" Then
        objAppointment.Delete
        Me!AddedToOutlook = False
        MsgBox "Appointment Deleted!", vbInformation
    Else
        MsgBox "Could not find appointment", vbInformation
    End If
 
    Set objAppointment = Nothing
    Set objAppointments = Nothing
 
End Sub
 
Hi

1. When creating your appointment check with
Code:
msgbox Me!RoomRequestID.Value             
.Mileage = Me!RoomRequestID.Value             
.Save             
msgbox .Mileage
.Close (olSave)
if you have an id in your control. Also that mileage actually has something in it.

2. I have a feeling you might have to .Send it. Keep it in mind if other things fail.

3. check that "objAppointments" is NOT nothing.

4. Otherwise you code looks ok. I think you are doing something silly and forgetting it. You might have to create an Outlook item with something you for sure know exists like a subject and search for this.

5. I hope you are deleteing and emptying from your deleted items calendar items with the SAME id. You code is only set up for ONE result not an array.
 
Thanks Darbid.

The code above creates the appointment OK. It's deleting it that I'm having a problem with.
Code:
sFilter = "[Mileage] = " & Me!RoomRequestID.Value & ""
    Set objAppointment = objAppointments.Items.Find(sFilter)
 
    If Not TypeName(objAppointment) = "Nothing" Then
objAppointment is "Nothing", so it doesn't delete. I'm not sure what I'm doing wrong. It picks up the mileage and sFilter = "[Mileage] = 3"

Thanks
 
Thanks Darbid.

The code above creates the appointment OK. It's deleting it that I'm having a problem with.

I understood you. I am guessing you are not making it correctly. Please go through my list of checks to narrow down the problem.
 
Thanks Darbid.

I'm at a disadvantage because I'm not on the network I'm developing for and have to rely on someone else to test the form.

I'll try the code on my own Outlook calendar and see if it can delete.

Thanks.
 
Thanks Darbid.

I'm at a disadvantage because I'm not on the network I'm developing for and have to rely on someone else to test the form.

I'll try the code on my own Outlook calendar and see if it can delete.

Thanks.
That is a good idea, and maybe try it with an email instead. It is identical just you will not have the folder part and you will create an email.
 

Users who are viewing this thread

Back
Top Bottom