Solved

VBA Change the calendar folder in which to add appointment

Posted on 2009-07-07
11
497 Views
Last Modified: 2013-11-27
I need to add an appointment to a specific calendar in Outlook 2007 using VBA from MS Access 2007. The code below works fine for the default calendar. I have managed to programatically add a calender, i now need to able to place an appointment in the newly created calendar
Dim objNS As NameSpace
Dim objFolder As Outlook.Folder
 Dim objItem As Outlook.AppointmentItem
 Set objNS = Outlook.GetNamespace("MAPI")
 Set objFolder = obNS.GetDefaultFolder(olFolderCalendar)
       ' In here need to change to a sub folder of the default called 'Room Booking'
Set objItem = Outlook.CreateItem(olAppointmentItem)
              With objItem
             ........... add item fields here

Open in new window

0
Comment
Question by:downehouse
[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
  • 6
  • 5
11 Comments
 
LVL 20

Expert Comment

by:darbid73
ID: 24794879

The way I do this is by the names of the folders

set up a few folder objects

Dim objFolder1 As Outlook.MAPIFolder
Dim objFolder2 As Outlook.MAPIFolder
Dim objFolder3 As Outlook.MAPIFolder

and then you need the names of them, I am working on a non english computer so I am not sure of the inbox name I think it might be inbox and then the users name.

Then the Folder calendar and then if that has sub folders get the named one called Room Booking.

objFolder3 you can then use.

Set objFolder1 = objNS.Folders("YourInboxName")
Set objFolder2 = objFolder1.Folders("Calendar")
Set objFolder3 = objFolder2.Folders("Room Booking")

Open in new window

0
 

Author Comment

by:downehouse
ID: 24794962
Many thanks, this certainly assigns the names to the objects but when you go add an appointment it still adds it to the default calendar. How does one ensure the folder you select is the one to use for the new appoinments?
0
 

Author Comment

by:downehouse
ID: 24794986
Sorry meant to say as per line 7 in code snippet I posted
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:darbid73
ID: 24795041
mmmmm are you sure

If Not objFolder3 Is Nothing Then
            Set objAppt = objFolder3.Items.Add
            If Not objAppt Is Nothing Then
                With objAppt
                    .MeetingStatus = olMeeting
                    .Subject = "Loser Conference"
                    .Start = "07/07/2009 17:00:00"
                    .Body = "You got First Place"
                    .Duration = 1400
                    .Location = "France Paris"
                    .ReminderMinutesBeforeStart = 60
                    .BusyStatus = olTentative
                    '.RequiredAttendees = "" 'put your email address here and it will send a request to you too
                    .Display
                End With
            End If
        End If

Open in new window

0
 
LVL 20

Expert Comment

by:darbid73
ID: 24795047
ahh line 7 in your snipet is never going to work with another folder.
0
 

Author Comment

by:downehouse
ID: 24795086
Your line 2: is maybe the answer, will try that in a minute
0
 
LVL 20

Accepted Solution

by:
darbid73 earned 500 total points
ID: 24795121
sorry you use a different name objAppt is objItem
0
 

Author Comment

by:downehouse
ID: 24795189
Amazing! it works, thank you so much.
0
 

Author Closing Comment

by:downehouse
ID: 31600586
Many thanks
0
 
LVL 20

Expert Comment

by:darbid73
ID: 24795203
do not forget that you should put some more of these so that you do not get any nasty errors

"If Not YOUROBJECTNAME Is Nothing Then"

0
 

Author Comment

by:downehouse
ID: 24795225
Will do, good tip.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

632 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