Thanks Sue - Here is cut down code as requested [ it does the add's OK but
not the delete's - fails on Set objAppointment =
objOutlook.Session.GetItemFromID(CalEntryID) ] :-
Dim objOutlook As Outlook.Application
Dim objCalendar As Object
Dim objAppointment As Object
Dim CalEntryID as Variant
Dim CalEntryIDR as Object
Dim SQLcmd as String
Set objOutlook = New Outlook.Application
Set objCalendar = objOutlook.Session.GetDefaultFolder(olFolderCalendar)
Select Case Action
Case "A"
cc = 0
Do While cc <= 2
Set objAppointment = objCalendar.Items.Add
With objAppointment
.Subject = "Test"
.Start = Date + cc
.AllDayEvent = True
End With
objAppointment.Close olSave
CalEntryID = objAppointment.EntryID
SQLcmd = "Insert into table tblx (EN,EI) values ('" & cc & "', '" &
CalEntryID & "')"
Docmd.RunSQL SQLcmd
cc = cc + 1
Loop
Case "D"
cc = 0
Do While cc <= 2
CalEntryID = DLookup("[EI]", "tblx", "[EN] = " & cc)
Set objAppointment = objOutlook.Session.GetItemFromID(CalEntryID)
objAppointment.Delete
cc = cc + 1
Loop
End Select
Set objAppointment = Nothing
Set objOutlook = Nothing
---------
"Sue Mosher [MVP-Outlook]" wrote:
> Show the code used to instantiate the Namespace and to save the items and
> get their EntryIDs.
>
> GetItemFromID returns an object. You need to use Set:
>
> Set CalEntryIDR = objNS.GetItemFromID(CalEntryID)
>
> --
> Sue Mosher, Outlook MVP
> Author of
> Microsoft Outlook Programming - Jumpstart for
> Administrators, Power Users, and Developers
> http://www.outlookcode.com/jumpstart.aspx
>
>
> "Andy" <(E-Mail Removed)> wrote in message
> news:F52F1C45-D96D-416F-8B3F-(E-Mail Removed)...
> > Sue - Sorry to push a bit more on this subject but it is interesting.
> > Firstly, I took your advice and looked at the VBA help files to work out
> > the
> > syntax of the various methods. I did struggle with Namespace though and
> > found
> > that I had to use Session instead.
> >
> > Anyway - I created 3 Appointment items one after the other and saved each
> > before obtaining their EntryID - suprisingly each EntryID was the same
> > even
> > though the 3 appointments were on different days albeit with the same
> > Subject
> > for each.
> >
> > I stored these away but when I came to later use them to delete the
> > appointments, I got a failure when I tried to set a variable as follows :-
> >
> > CalEntryIDR = objOutlook.Session.GetItemFromID(CalEntryID) ' CalEntryID is
> > the long EntryID value
> >
> > Also when I actually got this statement to work (just after creating the
> > appointment) the returned value was the Subject of the appointment ???
> >
> > Any ideas? Especially the difference between Namespace and Session and why
> > the 3 IDs were the same above.
> >
> > Thanks.
> >
> > The variable CalEntryID contains the long EntryID value.
> > "Sue Mosher [MVP-Outlook]" wrote:
> >
> >> When in doubt, check the object browser: Press ALt+F11 to open the VBA
> >> environment in Outlook, then press F2. Switch from <All Libraries> to
> >> Outlook to browse all Outlook objects and their properties, methods, and
> >> events. Select any object or member, then press F1 to see its Help topic.
> >>
> >> "Andy" <(E-Mail Removed)> wrote in message
> >> news:56FDB3C3-9810-4877-A442-(E-Mail Removed)...
> >> > Thanks Sue - good idea.
> >> >
> >> > I'm OK with obtaining and storing the EntryID for later use but could
> >> > you
> >> > help more with the syntax with Namespace.GetItemFromID and
> >> > AppointmentItem.Delete - I'm not so familar with these two contructs.
> >> >
> >> > Regards - Andy.
> >> >
> >> > "Sue Mosher [MVP-Outlook]" wrote:
> >> >
> >> >> Delete it in what context? If you get the item's EntryID after saving
> >> >> it
> >> >> and
> >> >> store that in your Access database, you can return the same item with
> >> >> the
> >> >> Namespace.GetItemFromID and then delete it with the
> >> >> AppointmentItem.Delete
> >> >> method.
> >> >>
> >> >>
> >> >> "Andy" <(E-Mail Removed)> wrote in message
> >> >> news
B7F9858-6C2B-4E9B-A3EF-(E-Mail Removed)...
> >> >> >I have successfully added an All Day appointment for tomorrow in
> >> >> >Outlook
> >> >> >from
> >> >> > Access using :-
> >> >> >
> >> >> > --------------
> >> >> >
> >> >> > Dim objOutlook As Outlook.Application
> >> >> > Dim objCalendar As Object
> >> >> > Dim objAppointment As Object
> >> >> >
> >> >> > Set objOutlook = New Outlook.Application
> >> >> > Set objCalendar =
> >> >> > objOutlook.Session.GetDefaultFolder(olFolderCalendar)
> >> >> >
> >> >> > Set objAppointment = objCalendar.Items.Add
> >> >> > With objAppointment
> >> >> > .Subject = "Test"
> >> >> > .Start = Date + 1
> >> >> > .AllDayEvent = True
> >> >> > End With
> >> >> > objAppointment.Close olSave
> >> >> > Set objAppointment = Nothing
> >> >> > Set objOutlook = Nothing
> >> >> >
> >> >> > ---------
> >> >> >
> >> >> > Can anyone help me with the code to delete the same appointment
> >> >> > using
> >> >> > VBA?
> >> >> >
> >> >> > Thanks.
> >> >> >
> >> >> >
> >> >> >
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>