CDO 1.21 User Options Best Practices

I worked a case this weekend where a product used to synchronize calendars between Exchange 5.5 and Exchange 2003 was setting CDO's user options to GMT and then not setting it back.  This of course would have no affect on the user if they were in GMT but it was causing CDO to render Calendar items in GMT time instead of the local time of the user, in this case Eastern.

To avoid this problem in the future, CDO applications should always set the user options back to their original values before ending the application.  To me this just makes logical sense, but hey what do I know.  Here is some sample code to add to your CDO applications if you are doing this:

    Dim objSession
    Dim tmzUser As Long
    Const tmzGMT = &H1
   
    Set objSession = CreateObject("MAPI.Session")
   
    ' Get the user's current timezone
    tmzUser = objSession.GetOption("TimeZone")
   
    ' Set the timezone to whatever you would like in this
    ' case we want to use GMT
    objSession.SetOption "TimeZone", tmzGMT
   
    ' Do something
        
    ' Now set the TimeZone back what it was
    objSession.SetOption "TimeZone", tmzUser
   
    Set objSession = Nothing