More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

share code 22-Jan-2019 17:54

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

Code level: advanced    Code area: Outlook Form Design Printer Friendly Version
Title: Set default form for a folder using CDO 1.21
Description: This sample uses CDO 1.21 to set the default form for a folder. It does not do any checking to determine whether such a form actually exists.
Date: 29-Jun-2006  14:10
Code level: advanced
Code area: Outlook Form Design
Posted by: Sue Mosher
This message is displayed as VB.NET
 Sub SetDefaultFormFolder(fld As Outlook.MAPIFolder, formClass As String, formName As String)
    Dim cdoFld As MAPI.folder
    Dim cdoSession As MAPI.Session
    Dim fld1 As MAPI.Field
    Dim fld2 As MAPI.Field
    Const PR_DEF_POST_MSGCLASS = &H36E5001E
    Const PR_DEF_POST_DISPLAYNAME = &H36E6001E
    On Error Resume Next

    Set cdoSession = CreateObject("MAPI.Session")
    cdoSession.Logon "", "", False, False
    Set cdoFld = cdoSession.GetFolder(fld.EntryID, fld.StoreID)
    If Not cdoFld Is Nothing Then
        Set fld1 = cdoFld.Fields(PR_DEF_POST_MSGCLASS)
        If fld1 Is Nothing Then
            Set fld1 = cdoFld.Fields.Add(PR_DEF_POST_MSGCLASS, formClass)
        Else
            fld1.Value = formClass
        End If
        Set fld2 = cdoFld.Fields(PR_DEF_POST_DISPLAYNAME)
        If fld2 Is Nothing Then
            Set fld2 = cdoFld.Fields.Add(PR_DEF_POST_DISPLAYNAME, formName)
        Else
            fld2.Value = formName
        End If
        cdoFld.Update True, True
    End If
    cdoSession.Logoff
    Set cdoSession = Nothing
    Set fld1 = Nothing
    Set fld2 = Nothing
    Set cdoFld = Nothing
End Sub
All 11comments
Page [ 1 2 Next >>  
  29-Jun-2006  14:13   
Notes on the code:

1) This code requires a reference in the project to the Collaboration Data Objects (CDO 1.21) library. This is an optional component of Outlook 2003 and earlier versions and available as a separate download for Outlook 2007. See http://www.outlookcode.com/d/cdo.htm

2) Sample VBA usage:

    SetDefaultFormFolder Application.ActiveExplorer.CurrentFolder, "IPM.Appointment.ThisLocation", "This Location"

2)
  01-Sep-2006  09:55   
Hola

1) Los procedimientos con CDO como realizas la llamada a objeto???? lo llamas desde las referencias para que te carge alguna libreria en especifica????
yo Trabajo con las mapi pero mi duda es de que si tu con CDO te puedes conectar directamente a otra bandeja que no sea la bandeja de entrada.

2) al utilizar Set cdoFld = cdoSession.GetFolder(fld.EntryID, fld.StoreID) te crea la identidad + storeid
tu como puedes comprobar que Mapi trabaje independiente de la bandeja del Outlook???
porfa favor de responder
  01-Sep-2006  11:49   
When used in Outlook VBA, as this sample was designed to do, the CDO Session uses the same mail profile as the Outlook session, and thus has access to exactly the same folders as the Outlook session. CDO, of course, also supports invoking Session.Logon with arguments that pass the server and alias names, so that you can log onto any mailbox and get whatever access there that the logged in Windows user has.

Don't forget that the machine needs to have CDO 1.21 installed or this code won't work.
  07-May-2007  21:53   
For an Outlook 2007 version that doesn't use CDO, see http://www.outlookcode.com/codedetail.aspx?id=1594
  08-Aug-2007  09:56   
Sue,

Any reason this code would not work as vbscript inside of a windows installer package?

I got the code working outside of the installer package (by just double clicking the vbs file) -- but once the file get incorporated into the windows installer package it fails on the following line

 Set objSession = CreateObject("MAPI.Session")

I'm thinking it may be security related??

Thanks,

Jim
  08-Aug-2007  11:00   
Jim, if CDO 1.21 is not already installed on the machine, that statement would fail.
  08-Aug-2007  11:52   
Ah, you have it running in a standalone script but not in the installer package. Sorry, but I don't know anything about running code from a Windows Installer package. Scripting would generally be considered less secure, so I don't think it's a security issue.
  03-Mar-2008  03:22   
Hi,

I have several computers that do not have CDO installed, and don't want to force the users to install CDO in order for my application to work.
What would the code look like if I were to use Outlook Redemption 4.4.x from Dmitry Streblechenko ?
  03-Mar-2008  08:01   
Using Redemption, you'd return an RDOFolder object using any of the methods listed at http://www.dimastr.com/redemption/rdo/RDOFolder.htm and then use its Fields collection, just as you would CDO's.
  03-Mar-2009  10:09   
Should I put this code in ThisOutlookSession module?
And where do I call this procedure from?

Thank you!
Page [ 1 2 Next >>