Programming outlook calendar

V

vegardhv

Hey

This might not be the correct place to ask for this, if it's not then
I apologize and humbly ask you to maybe direct me to the correct
place/
newsgroup.

I'm working with automation in the outlook calendar (MS Access using
visual basic).

My goal is to put appointments into a shared calendar. I've achieved
putting them into the default calendar, but I want it to go into
another one - let's say it's name is "Shared Calendar". I've been
trying lot of things without success - here is my code that puts it
into the default calendar. How do I get it to put the appointments
into a shared calendar ?

I tried to use:

Set ocalItems = oNameSpace.Folder("Shared Calendar").Items

instead of

Set ocalItems = oNameSpace.GetDefaultFolder(olFolderCalendar).Items

Below is my code that works for the default calendar in outlook .
Sorry if I sound n00bish.

Hope any of you bright minds can help :)

regards
Vegard

------------------------------------------------------------------------------------------------------

Dim oOutlook As New outlook.Application

Dim oNameSpace As NameSpace
Dim Appointment As Object
Dim ocalItems As Items
Dim AppointmentDate As String
Dim rs As Recordset
Dim db As Database
Dim sql As String
Dim today As Date
Dim myRecipient As outlook.Recipient
Dim olApp As outlook.Application

today = Now()

Set oNameSpace = oOutlook.GetNamespace("MAPI")

Set ocalItems = oNameSpace.GetDefaultFolder(olFolderCalendar).Items
AppointmentDate = Now() - 1
Set Appointment = ocalItems.GetFirst

Do While Not (Appointment Is Nothing)
If Appointment.Start > AppointmentDate Then
Appointment.Delete
End If
Set Appointment = ocalItems.GetNext

Loop

Set olApp = CreateObject("Outlook.Application")

Set olAppt = olApp.CreateItem(olAppointmentItem)

' Set start time for 2-minutes from now...
'olAppt.Start = Now() + (2# / 24# / 60#)
olAppt.Start = Format(rs("dato_begravelse") & " " &
rs("klokkeslett_begravelse"), "dd/mm/yyyy hh:mm")

' Setup other appointment information...
With olAppt
.Duration = 60
.Subject = "Begravelse"
.Body = "Begravelse for " & rs("fornavn_avdøde") & " " &
rs("etternavn_avdøde")
.Location = rs("kirkenavn")
.ReminderMinutesBeforeStart = 15
.ReminderSet = True
End With

' Save Appointment...
olAppt.Save

Set olApp = Nothing

Set Appointment = Nothing
Set ocalItems = Nothing
Set oNameSpace = Nothing
Set oOutlook = Nothing
 
K

Ken Slovak - [MVP - Outlook]

The best place for programming questions is a programming group such as
microsoft.public.outlook.program_vba.

To work in a shared calendar, assuming you have adequate permissions, use
the NameSpace.GetSharedDefaultFolder() method. You supply that method with
the Recipient object that represents the owner of that mailbox.




Hey

This might not be the correct place to ask for this, if it's not then
I apologize and humbly ask you to maybe direct me to the correct
place/
newsgroup.

I'm working with automation in the outlook calendar (MS Access using
visual basic).

My goal is to put appointments into a shared calendar. I've achieved
putting them into the default calendar, but I want it to go into
another one - let's say it's name is "Shared Calendar". I've been
trying lot of things without success - here is my code that puts it
into the default calendar. How do I get it to put the appointments
into a shared calendar ?

I tried to use:

Set ocalItems = oNameSpace.Folder("Shared Calendar").Items

instead of

Set ocalItems = oNameSpace.GetDefaultFolder(olFolderCalendar).Items

Below is my code that works for the default calendar in outlook .
Sorry if I sound n00bish.

Hope any of you bright minds can help :)

regards
Vegard

------------------------------------------------------------------------------------------------------

Dim oOutlook As New outlook.Application

Dim oNameSpace As NameSpace
Dim Appointment As Object
Dim ocalItems As Items
Dim AppointmentDate As String
Dim rs As Recordset
Dim db As Database
Dim sql As String
Dim today As Date
Dim myRecipient As outlook.Recipient
Dim olApp As outlook.Application

today = Now()

Set oNameSpace = oOutlook.GetNamespace("MAPI")

Set ocalItems = oNameSpace.GetDefaultFolder(olFolderCalendar).Items
AppointmentDate = Now() - 1
Set Appointment = ocalItems.GetFirst

Do While Not (Appointment Is Nothing)
If Appointment.Start > AppointmentDate Then
Appointment.Delete
End If
Set Appointment = ocalItems.GetNext

Loop

Set olApp = CreateObject("Outlook.Application")

Set olAppt = olApp.CreateItem(olAppointmentItem)

' Set start time for 2-minutes from now...
'olAppt.Start = Now() + (2# / 24# / 60#)
olAppt.Start = Format(rs("dato_begravelse") & " " &
rs("klokkeslett_begravelse"), "dd/mm/yyyy hh:mm")

' Setup other appointment information...
With olAppt
.Duration = 60
.Subject = "Begravelse"
.Body = "Begravelse for " & rs("fornavn_avdøde") & " " &
rs("etternavn_avdøde")
.Location = rs("kirkenavn")
.ReminderMinutesBeforeStart = 15
.ReminderSet = True
End With

' Save Appointment...
olAppt.Save

Set olApp = Nothing

Set Appointment = Nothing
Set ocalItems = Nothing
Set oNameSpace = Nothing
Set oOutlook = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top