Link to home
Start Free TrialLog in
Avatar of edmacey
edmacey

asked on

Choose if also want to add appointment to second calendar - Outlook

I maintain my own calendar within outlook and am also required to add appointments to a 'marketing calendar' if they are marketing related so we can see in a flash whether our small company (5 people) are doing enough meeting and greeting.

At the moment I either remember to create the appointment in the marketing calendar and invite myself or I forget and just create it in my calendar and then have to copy it across.

What would be really handy would be a small box or pop up which asks if I want to add appointment to the marketing calendar.

Does anyone know how to do this? I'm quite familiar with designing forms. The marketing calendar is held in shared folders on the Exchange server (2003) and I am running Outlook 2007.

I do have VSTO if that helps.

Thanks Ed.
Avatar of David Lee
David Lee
Flag of United States of America image

Hi, Ed.

How about an even simpler solution?  If you categorized these appointments (i.e. add a category called "Marketing" and assign it to all marketing appointments), then we could use a bit of code to add these appointments to the Marketing calendar automatically.  That'd save you from having to answer a question each time.
Avatar of edmacey
edmacey

ASKER

Dear BlueDevilFan;

That sounds like a fab idea. My only reservation is that it still requires the user to remember to categorise the appointment where as a pop up box forces them to make a decision there and then.

Unless you were forced to classify the appointment before you closed it?
There are several ways you can handle this.

1.  Create a custom form.  Add code to the form's Save event that displays a dialog-box asking if the item should be copied to the marketing calendar.  If the user responds yes, then create a copy of the item and move it to the marketing calendar.  The problem I see with this approach is that you'll get prompted each time you make a change to the appointment.  If you answer yes more than once, then you'll end up with multiple copies of the appointment on the marketing calendar.  Avoiding that means more code to see if the appointment is already on the marketing calendar and updating it (more code) or deleting it first to avoid multiple copies.  You also have to replace the default appointment form with your form on all computers that need this capability

2.  Create an Outlook add-in or macro.  It would monitor the inspector windows for appointments.  When it sees you saving an appointment it would perform the same steps as the custom form.  However, because you've moved the logic to an add-in you don't have to deploy a custom form or replace Outlook's built-in appointment form.  Of course you do have to deploy the add-in or macro code.

3.  Create an Outlook add-in or macro.  It would monitor your calendar's items collection watching for the ItemAdd event.  When it sees one it displays the diaalog-box asking if this is form marketing.  If you say yes, then  it copies the item to the marketing calendar.  Because it only monitors for new items, it doesn't ask you the question when you change an item.  It also doesn't require any changes to the form, but does require deploying the add-in or macro code.

Avatar of edmacey

ASKER

Dear BlueDevilFan,

Is option 3 the easier of the 3 to achieve? I wouldn't know where to start with the code though. I do already have an inspectors watch running for task items which calls up projectwrapper. Should I post the code? Are you able to have inspector/monitor looking for more than one thing?

Thanks Ed.
Good morning, Ed.

Option 3 is the easiest to achieve if starting from scratch.  Since you already have code that's watching inspectors it may be easier to modify it.  Yes, an inspector monitor can watch for multiple items.  Please post the code.  I'll take a look and see how difficult it'd be to use it to accomplish this.
Avatar of edmacey

ASKER

Good morning (although it is nearly tea time where I am!)

The inspectors code I have is below, would you like TaskEmailer as well, the projectwrapper it opens?
Option Explicit
Dim WithEvents inspectors As inspectors
Dim WithEvents project As TaskItem
Dim root As folder
 
Private Sub Application_Startup()
    Set inspectors = Application.inspectors
    Set root = Application.Session.Folders("Business Contact Manager")
    Set project = root.Folders("Business Projects").items(1)
End Sub
Private Sub inspectors_NewInspector(ByVal inspector As inspector)
    If inspector.CurrentItem.Class <> olTask Then Exit Sub
    Dim oTaskItem As TaskItem
    Set oTaskItem = inspector.CurrentItem
    If oTaskItem.MessageClass <> "IPM.Task.BCM.ProjectTask" Then Return
    Dim oProjectWrapper As New TaskEmailer
    oProjectWrapper.Init inspector
End Sub

Open in new window

This is too specific to the one task.  I think it'd be easier to go with what I proposed in #3.  The code for that is below.  It must go in the ThisOutlookSession module.  The code monitors the calendar for new Items.  When one appears it asks if the item should be copied to the Marketing folder.  If the answer is "yes", then it disables monitoring (to avoid triggering the ItemAdd event a 2nd time), makes a copy of the item, and moves that copy to the Marketing calendar.
Dim WithEvents olkCalendar As Outlook.Items
 
Private Sub Application_Quit()
    Set olkCalendar = Nothing
End Sub
 
Private Sub Application_Startup()
    Set olkCalendar = Outlook.Session.GetDefaultFolder(olFolderCalendar).Items
End Sub
 
Private Sub olkCalendar_ItemAdd(ByVal Item As Object)
    Dim olkCopy As Outlook.AppointmentItem
    If (MsgBox("Copy this item to the Marketing calendar?", vbQuestion + vbYesNo, "Add to Marketing Calendar") = vbYes) Then
        Set olkCalendar = Nothing
        Set olkCopy = Item.Copy
        'Change the folder path on the next line'
        olkCopy.Move Outlook.Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Marketing")
        Set olkCalendar = Outlook.Session.GetDefaultFolder(olFolderCalendar).Items
    End If
    Set olkCopy = Nothing
End Sub

Open in new window

Avatar of edmacey

ASKER

That's brilliant, I used your code for finding the calendar path from a different post and found that the path for the marketing calendar is

\\Public Folders\Favorites\Marketing Calendar

how do i integrate this into the folder path line as it returns errors if I just copy it into the folder name section.

olkCopy.Move Outlook.Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("\\Public Folders\Favorites\Marketing Calendar")

Thanks Ed.
I'm not sure that's a valid path.  Public folder paths are typically "\\Public Folders\All Public Folders\Marketing Calendar".  The path you gave looks like it might be a public folder favorite.  Not sure that'll work.  It might.  I don't think I've ever tried accessing a folder in that way.  But, it won't work with that code.  Try this instead.

olkCopy.Move Outlook.Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Marketing Calendar")
Avatar of edmacey

ASKER

Thanks BlueDevilFan,

The above bit didn't work.

Sorry the actual non favourite path is

\\Public Folders\All Public Folders\IPT Calendar\Marketing Calendar

So how would I integrate that? Thanks Ed.
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of edmacey

ASKER

I had tried that before you had suggested it and it hadn't worked and then tried it again when you suggested it and it didn't work. But then created new sub folder with name test and new calendar with name test and it worked, and then called test test 1 to see if it was the space that was creating a problem but it wasn't. So renamed it all to IPT Calendar and Marketing Calendar and now it works!
Thanks so much. Ed.
You're welcome, Ed.  Cheers!