Setting Folder Aging Properties Prob

L

Lando

I am trying to set the default autoarchive settings for user created folders
within Outlook 2003 using the code below yet I keep getting the error Object
doesn't support this property or method on the line: objMessage.Add
"IPC.MS.Outlook.AgingProperties". Does anyone know what is wrong here? I
would also like to change it to be recursive in case of subfolders. Any
revised sample code would be appreciated.

Thanks,
Lando
------------------------------------------------

Sub Arc()

' MAPI property tags for aging properties
Const CdoPR_AGING_PERIOD = &H36EC0003
Const CdoPR_AGING_GRANULARITY = &H36EE0003
Const CdoPR_AGING_PATH = &H6856001E
Const CdoPR_AGING_ENABLED = &H6857000B
Const CdoPR_AUTOARCHIVE_TYPE = &H685E0003
Const CdoPR_AGING_AGE_FOLDER = &H6857000B
Const CdoPR_CONTAINER_CLASS = &H3613001E

' Properties for aging granularity
Const AG_MONTHS = 0
Const AG_WEEKS = 1
Const AG_DAYS = 2

' Declare variables
Dim objSession As MAPI.Session
Dim objInfoStore As Object
'Dim objInboxFolder As MAPI.Folder
'Dim colFolders As MAPI.Folders


' Initialize variables
Set objSession = Nothing
Set objInboxFolder = Nothing

' Create CDO session and logon
Set objSession = New MAPI.Session

' CDO session logon
objSession.Logon "", "", ShowDialog:=True, NewSession:=False

Set objInfoStore = objSession.InfoStores.Item(1)
Set objRootFolder = objInfoStore.RootFolder
Set colFolders = objRootFolder.Folders

Set objFolCalendar = objSession.GetDefaultFolder(CdoDefaultFolderCalendar)
Set objFolContacts = objSession.GetDefaultFolder(CdoDefaultFolderContacts)
Set objFolDeleted =
objSession.GetDefaultFolder(CdoDefaultFolderDeletedItems)
Set objFolJournal = objSession.GetDefaultFolder(CdoDefaultFolderJournal)
Set objFolNotes = objSession.GetDefaultFolder(CdoDefaultFolderNotes)
Set objFolSent = objSession.GetDefaultFolder(CdoDefaultFolderSentItems)
Set objFolTasks = objSession.GetDefaultFolder(CdoDefaultFolderTasks)
Set objFolInbox = objSession.GetDefaultFolder(CdoDefaultFolderInbox)
Set objFolOutbox = objSession.GetDefaultFolder(CdoDefaultFolderOutbox)


For Each objFolder In colFolders

' Get hidden message collection
Set objHiddenMessages = objFolder.HiddenMessages

' Loop through the hidden messages collection
For Each objMessage In objHiddenMessages


Select Case objFolder.ID
Case objFolInbox.ID
Case objFolOutbox.ID
Case objFolJournal.ID
Case objFolContacts.ID
Case objFolCalendar.ID
Case objFolDeleted.ID
Case objFolNotes.ID
Case objFolTasks.ID
Case objFolSent.ID
Case Else

If Not objMessage.Type = "IPC.MS.Outlook.AgingProperties" Then
objMessage.Add "IPC.MS.Outlook.AgingProperties"
End If

' Change the autoarchive mode (none,default,param)
objMessage.Fields.Item(CdoPR_AUTOARCHIVE_TYPE).Value = 0

' Change aging properties to 14 months/weeks/days
objMessage.Fields.Item(CdoPR_AGING_PERIOD).Value = 3

' Change aging granularity to days
objMessage.Fields.Item(CdoPR_AGING_GRANULARITY).Value = AG_MONTHS

' Change the path to the archive file
objMessage.Fields.Item(CdoPR_AGING_PATH).Value = "C:\Temp\archive.pst"

' Enable aging for this folder
objMessage.Fields.Item(CdoPR_AGING_ENABLED).Value = True

' Enable aging age for this folder
objMessage.Fields.Item(CdoPR_AGING_AGE_FOLDER).Value = True

' Update hidden message
objMessage.Update True, True

'End If
End Select
Next

Next
End Sub
 
M

Michael Bauer

Hi Lando,

I never worked with HiddenMessages so far and can´t find the class in
the Objectbrowser. Is it the Messages class, too?

If so, not objMessage, but objMessages has the Add method, and you´d
need to re-design your code: You´d need to loop through the whole
collection for searching the specified type and add it only if there is
no match. Maybe the loop have not to be if you can use the Item method?

BTW: If this is the complete code why do you check the objFolder.ID in
each objMessage loop?
 
K

Ken Slovak - [MVP - Outlook]

HiddenMessages is a collection in CDO 1.21 of the Folder object, it's what's
shown in OutlookSpy as Associated Messages and contains all the hidden items
in the folder.

As Michael said, the error is coming from Message.Add, which doesn't exist.
Once you get your Messages collection from HiddenMessages you would use
Messages.Add.

There's some information about the properties for archiving at
www.cdolive.com/cdo10.htm. Also, take a look at
http://www.cdolive.com/archiveviewer.htm, which uses those properties to
view autoarchive settings. It does a lot of what you want to do.
 
L

Lando

Thanks for the information! Unfortunately I'm not that experienced with VB.
I've looked at the code from the links you gave me and below is what I have
written on my own. I keep getting the error [Collaboration Data Objects -
[MAPI_E_NOT_FOUND(8004010F)] when I run the code below.
If I change:
Set objField = objFields.Item(CdoPR_AGING_FILENAME)
to
Set objField = objFields.Item(CdoPR_AUTOARCHIVE_TYPE)
or any other value it works.

I know I'm asking alot but does anyone have some sample code or could modify
my code below that would apply archive settings to a folder or all folders
in a mailbox with the values I chose? It seems I keep missing things I think
a savvy programmer would catch and could do much faster than I could ever
hope to.

Thanks again for all your help! I really appreciate it!

Lando
----------------------------------------------

Sub LandoCode()

' MAPI property tags for aging properties
Const CdoPR_AGING_PERIOD = &H36EC0003
Const CdoPR_AGING_GRANULARITY = &H36EE0003
Const CdoPR_AGING_PATH = &H6856001E
Const CdoPR_AGING_ENABLED = &H6857000B
Const CdoPR_AUTOARCHIVE_TYPE = &H685E0003
Const CdoPR_AGING_AGE_FOLDER = &H6857000B
Const CdoPR_CONTAINER_CLASS = &H3613001E
Const CdoPR_AGING_FILENAME = &H6856001E

' Properties for aging granularity
Const AG_MONTHS = 0
Const AG_WEEKS = 1
Const AG_DAYS = 2

' Declare variables
Dim objSession As MAPI.Session
Dim objInfoStore As Object
Dim objHiddenMessages As MAPI.Messages
Dim objMessage As MAPI.Message
Dim objFields As MAPI.Fields

' Initialize variables
Set objSession = Nothing
Set objInboxFolder = Nothing

' Create CDO session and logon
Set objSession = New MAPI.Session

' CDO session logon
objSession.Logon "", "", ShowDialog:=True, NewSession:=False

' Get the inbox folder of a mailbox
Set objFolder = objSession.Inbox

' Get the hidden messages collection
Set objMessages = objFolder.HiddenMessages

' Loop through the hidden messages
For Each objMessage In objMessages

' Check the message class
If objMessage.Type = "IPC.MS.Outlook.AgingProperties" Then
MsgBox (objMessage.Type)
Set objFields = objMessage.Fields

Set objField = objFields.Item(CdoPR_AGING_FILENAME)
MsgBox (objField.Value)

' For Each objField In objFields
' MsgBox (objField.Value)
' Next
End If
Next

End Sub


Ken Slovak - said:
HiddenMessages is a collection in CDO 1.21 of the Folder object, it's
what's shown in OutlookSpy as Associated Messages and contains all the
hidden items in the folder.

As Michael said, the error is coming from Message.Add, which doesn't
exist. Once you get your Messages collection from HiddenMessages you would
use Messages.Add.

There's some information about the properties for archiving at
www.cdolive.com/cdo10.htm. Also, take a look at
http://www.cdolive.com/archiveviewer.htm, which uses those properties to
view autoarchive settings. It does a lot of what you want to do.
 
L

Lando

Whooohoo! Sorry about that but I finally got it to work. Now I've got 2 more
things to overcome with this. The first is how do I recursively go through
every folder in a mailbox and apply these settings? I'm sure someone has
some excellent efficient code to do this. Thanks in advance.....

The next may be a problem. We are using Outlook 2003 in cached mode. We use
cached mode because the Junk-Email filter requires it be turned on to
function. I can set the autoarchive settings and when cached mode is OFF the
settings are correct. However if I turn cached mode ON the settings are
incorrect. Is there some way to refresh this information in the cached
profile via VBA or some other way?

Thanks ahead of time for everyones help. You guys are the just awesome!

Thanks,
Lando

Ken Slovak - said:
HiddenMessages is a collection in CDO 1.21 of the Folder object, it's
what's shown in OutlookSpy as Associated Messages and contains all the
hidden items in the folder.

As Michael said, the error is coming from Message.Add, which doesn't
exist. Once you get your Messages collection from HiddenMessages you would
use Messages.Add.

There's some information about the properties for archiving at
www.cdolive.com/cdo10.htm. Also, take a look at
http://www.cdolive.com/archiveviewer.htm, which uses those properties to
view autoarchive settings. It does a lot of what you want to do.
 
M

Michael Bauer

Hi Lando,

for the first you can easily adapt this template:

' <Sample: Loop through the Outlook folders hierarchy for handling _
each folder item>
Public Sub HandleAllItems(oRoot As Outlook.NameSpace)
LoopFolders oRoot.Folders, True
End Sub

Private Sub LoopFolders(oFolders As Outlook.Folders, _
ByVal bRecursive As Boolean _
)
Dim oFld As Outlook.MAPIFolder

' Loop through all folders.
For Each oFld In oFolders
' Loop through folder items
LoopItems oFld.Items

If bRecursive Then
' Call this function again for going _
deeper into the object hierarchy.
LoopFolders oFld.Folders, bRecursive
End If
Next
End Sub

Private Sub LoopItems(oItems As Outlook.Items)
Dim obj As Object

For Each obj In oItems
Select Case True
Case TypeOf obj Is Outlook.MailItem
HandleMailItem obj
Case TypeOf obj Is Outlook.ContactItem
' Another method for handling ContactItems
' etc.
End Select
Next
End Sub

Private Sub HandleMailItem(oItem As Outlook.MailItem)
' Do s.th. with the object.
End Sub
' </Sample>

For the second please wait for Ken :)
 
K

Ken Slovak - [MVP - Outlook]

Gee, thanks, Michael :)

One thing to note with Michael's example is that it is using the Outlook
object model and not CDO 1.21 code to iterate the folders. Similar code
could be written using CDO code using the Folders collection of each loaded
InfoStore in the Session.InfoStores collection and iterating each Folder
object.

And conversion from CDO to Outlook or vice versa is by getting the folder
EntryID (ID in CDO) along with StoreID and then using
NameSpace.GetFolderFromID or Session.GetFolder.

If the specific InfoStore is a default Exchange mailbox the synching of the
offline store (OST) and the mailbox on the server would take place at
scheduled intervals. To synch at different intervals you could find the
CommandBarButton that corresponds to Send/Receive All and use that button's
Execute method. That should synch. For public folders you need to set the
store to download public folders, set the email account to synch the folders
of interest and to add the public folders to the public folder favorites
folder.
 
L

Lando

Ken Slovak - said:
Gee, thanks, Michael :)

One thing to note with Michael's example is that it is using the Outlook
object model and not CDO 1.21 code to iterate the folders. Similar code
could be written using CDO code using the Folders collection of each
loaded InfoStore in the Session.InfoStores collection and iterating each
Folder object.

And conversion from CDO to Outlook or vice versa is by getting the folder
EntryID (ID in CDO) along with StoreID and then using
NameSpace.GetFolderFromID or Session.GetFolder.

If the specific InfoStore is a default Exchange mailbox the synching of
the offline store (OST) and the mailbox on the server would take place at
scheduled intervals. To synch at different intervals you could find the
CommandBarButton that corresponds to Send/Receive All and use that
button's Execute method. That should synch. For public folders you need to
set the store to download public folders, set the email account to synch
the folders of interest and to add the public folders to the public folder
favorites folder.
 
L

Lando

Thank Ken,
Would you be able to show me some sample CDO code using the folders
collection method? I prefer using this method if possible. Also, the
send/receive does not update the archive settings set on the server. The
cached mode profile still retains the old settings. Do you know where these
are stored locally and if so is there a way to syncronize them?

Thanks,
Lando


Ken Slovak - said:
Gee, thanks, Michael :)

One thing to note with Michael's example is that it is using the Outlook
object model and not CDO 1.21 code to iterate the folders. Similar code
could be written using CDO code using the Folders collection of each
loaded InfoStore in the Session.InfoStores collection and iterating each
Folder object.

And conversion from CDO to Outlook or vice versa is by getting the folder
EntryID (ID in CDO) along with StoreID and then using
NameSpace.GetFolderFromID or Session.GetFolder.

If the specific InfoStore is a default Exchange mailbox the synching of
the offline store (OST) and the mailbox on the server would take place at
scheduled intervals. To synch at different intervals you could find the
CommandBarButton that corresponds to Send/Receive All and use that
button's Execute method. That should synch. For public folders you need to
set the store to download public folders, set the email account to synch
the folders of interest and to add the public folders to the public folder
favorites folder.
 
G

Guest

I AINT WORRYING ABOUT YOUR REPEAT CODE, BUT AS FOR THE
OBJECT ADD THIS, AND CHANGE TO READ



Sub Arc()

' MAPI property tags for aging properties
Const CdoPR_AGING_PERIOD = &H36EC0003
Const CdoPR_AGING_GRANULARITY = &H36EE0003
Const CdoPR_AGING_PATH = &H6856001E
Const CdoPR_AGING_ENABLED = &H6857000B
Const CdoPR_AUTOARCHIVE_TYPE = &H685E0003
Const CdoPR_AGING_AGE_FOLDER = &H6857000B
Const CdoPR_CONTAINER_CLASS = &H3613001E

' Properties for aging granularity
Const AG_MONTHS = 0
Const AG_WEEKS = 1
Const AG_DAYS = 2

' Declare variables
Dim objSession As MAPI.Session
Dim objInfoStore As Object
'Dim objInboxFolder As MAPI.Folder
' CDO session logon
'Dim colFolders As MAPI.Folders
Set objInboxFolder = Nothing
Set objSession = New MAPI.Session
objSession.Logon "", "", ShowDialog:=True, NewSession:=False
Set objInfoStore = objSession.InfoStores.Item(1)
Set objRootFolder = objInfoStore.RootFolder
Set colFolders = objRootFolder.Folders

Set objFolCalendar = objSession.GetDefaultFolder (CdoDefaultFolderCalendar)
Set objFolContacts = objSession.GetDefaultFolder (CdoDefaultFolderContacts)
Set objFolDeleted =
objSession.GetDefaultFolder(CdoDefaultFolderDeletedItems)
Set objFolJournal = objSession.GetDefaultFolder (CdoDefaultFolderJournal)
Set objFolNotes = objSession.GetDefaultFolder (CdoDefaultFolderNotes)
Set objFolSent = objSession.GetDefaultFolder (CdoDefaultFolderSentItems)
Set objFolTasks = objSession.GetDefaultFolder (CdoDefaultFolderTasks)
Set objFolInbox = objSession.GetDefaultFolder (CdoDefaultFolderInbox)
Set objFolOutbox = objSession.GetDefaultFolder (CdoDefaultFolderOutbox)


For Each objFolder In colFolders

' Get hidden message collection
Set objHiddenMessages = objFolder.HiddenMessages
|||DIM objMessage
|||SET objMessage
|||SET objMessageHidden as objMessage



' Loop through the hidden messages collection
For Each objMessage In objHiddenMessages


Select Case objFolder.ID
Case objFolInbox.ID
Case objFolOutbox.ID
Case objFolJournal.ID
Case objFolContacts.ID
Case objFolCalendar.ID
Case objFolDeleted.ID
Case objFolNotes.ID
Case objFolTasks.ID
Case objFolSent.ID
Case Else




If Not objMessage.Type
= "IPC.MS.Outlook.AgingProperties" Then
 
K

Ken Slovak - [MVP - Outlook]

There are all sorts of samples of CDO 1.21 code at www.cdolive.com/cdo5.htm.
I also had mentioned a sample for folder aging properties also located at
CDOLive.

Each folder's aging properties are stored in a hidden item in the folder (in
the HiddenMessages collection of that folder). When you are accessing the
store using cached mode you have access to the OST file and not directly to
the Exchange mailbox. The OST should synch to the mailbox at scheduled
intervals and a send/receive all usually does that synch.
 
K

Ken Slovak - [MVP - Outlook]

Gee is an expression meaning something like golly, an expression used to
express mild surprise or wonder politely.
 
M

Michael Bauer

Thanks for the translation. Unfortunately the important expressions are
not explained in my dictionary...
 
L

Lando

Thanks for the links Ken,
Unfortunately I can't get it to work. I keep getting different messages.
Could someone list some sample CDO code that would get a list of all folders
in a user's mailbox? This would greatly help me and I could modify the code
from there.

Also, when accessing the OST file while in cached mode the archive settings
are NOT correct. If I take the user out of cached mode the archive settings
are displayed correctly. The send/receive all does NOT sync the archive
settings. The server settings differ from the local OST file settings. Is
there a way to syncronize these?

Another way to do this may be to apply archive settings using Outlook's
built-in archive properties rather than using CDO to access the mail store
information. For example, I right-click on a folder and set the autoarchive
properties and click ok. Is there a way to do this via VB rather than using
the folders autoarchive property menus?

Thanks in advance for the help!
Lando
 
M

Michael Bauer

Hi Lando,

1) As I said you can easily adapt my sample. Just change the object
types from Outlook types into Mapi types. For Mapi the hierarchy is
Session/InfoStores/InfoStore/Folders/Folder/Messages.

If you have done that and still get errors then it would be helpful for
us if you say what type of errors you get.

2) Ken thinks: gee, but I still don´t know the answer :)

3) No way via the OOM. There would be a way with a lot of Win32 APIs and
a separate (EXE) thread. My strongly recommendation: Forget it :)
 
K

Ken Slovak - [MVP - Outlook]

Outlook's archive settings aren't exposed at all. You'd have to use some
other API or object model to get at them. The folder settings are accessible
using CDO or Redemption or Extended MAPI, the global settings are in the
registry.

I don't know of any ways to get around your cached problem if a synch isn't
matching the server side and local OST settings. The only thing I see in
your code that could be a problem is the assumption that the archive
properties you are accessing always will exist in the folders. In many cases
the properties won't exist until they are created. So you might want to try
getting a property or setting it and if you get an error then using the Add
method to add those properties to the folder.

For a CDO sample to iterate folders just use Michael's Outlook example and
change the types to CDO types. Otherwise the principles are identical.
 
L

Lando

One more tidbit of information on this. The CDO code to change the archive
properties does not work when in cached mode. You must be out of cached mode
for the settings to change. At least that appears to be what is happening
from what I can tell. Any suggestions?
 
K

Ken Slovak - [MVP - Outlook]

About the only thing I can think of other than using Extended MAPI is that
the latest version of Redemption seems to have a new
MAPIUtils.GetItemFromIDEx method that can read directly from the mailbox and
bypass the cache. That might work.
 
R

rbuckley

Did anyone ever get this working. I have tried scripting this as well.
The script runs, and processes all the folders in the mailbox. But, th
paths of the archive.pst never get changed.

Thanks,

Ric
 

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

Similar Threads


Top