#1
|
|||
|
|||
Setting Folder Aging Properties Prob
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(CdoDefaultFolderCalend ar) Set objFolContacts = objSession.GetDefaultFolder(CdoDefaultFolderContac ts) Set objFolDeleted = objSession.GetDefaultFolder(CdoDefaultFolderDelete dItems) Set objFolJournal = objSession.GetDefaultFolder(CdoDefaultFolderJourna l) Set objFolNotes = objSession.GetDefaultFolder(CdoDefaultFolderNotes) Set objFolSent = objSession.GetDefaultFolder(CdoDefaultFolderSentIt ems) 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).Val ue = 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).Va lue = 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).Val ue = True ' Update hidden message objMessage.Update True, True 'End If End Select Next Next End Sub |
#2
|
|||
|
|||
Re: Setting Folder Aging Properties Prob
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? -- Viele Grüße Michael Bauer |
#3
|
|||
|
|||
Re: Setting Folder Aging Properties Prob
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. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm |
#4
|
|||
|
|||
Re: Setting Folder Aging Properties Prob
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 |
#5
|
|||
|
|||
Re: Setting Folder Aging Properties Prob
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 - [MVP - Outlook]" <kenslovak@mvps.org> wrote in message news:ee1IBYaHFHA.400@TK2MSFTNGP14.phx.gbl... [quote]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. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm |
#6
|
|||
|
|||
Re: Setting Folder Aging Properties Prob
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 :-) -- Viele Grüße Michael Bauer |
#7
|
|||
|
|||
Re: Setting Folder Aging Properties Prob
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. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm |
#8
|
|||
|
|||
Re: Setting Folder Aging Properties Prob
Hi Ken,
Quote:
-- Viele Grüße Michael Bauer |
#9
|
|||
|
|||
Re: Setting Folder Aging Properties Prob
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 |
#10
|
|||
|
|||
Setting Folder Aging Properties Prob
I AINT WORRYING ABOUT YOUR REPEAT CODE, BUT AS FOR THE
OBJECT ADD THIS, AND CHANGE TO READ Quote:
|||SET objMessageHidden as objMessage Quote:
Quote:
|
#11
|
|||
|
|||
Re: Setting Folder Aging Properties Prob
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. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm |
#12
|
|||
|
|||
Re: Setting Folder Aging Properties Prob
Gee is an expression meaning something like golly, an expression used to
express mild surprise or wonder politely. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm |
#13
|
|||
|
|||
Re: Setting Folder Aging Properties Prob
Thanks for the translation. Unfortunately the important expressions are
not explained in my dictionary... -- Viele Grüße Michael Bauer |
#14
|
|||
|
|||
Re: Setting Folder Aging Properties Prob
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 |
#15
|
|||
|
|||
Re: Setting Folder Aging Properties Prob
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 :-) -- Viele Grüße Michael Bauer |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
setting up a program to run from your calendar | mattz76 | Outlook | 0 | 08-22-2007 09:13 PM |
Can I get some help setting this up please? | Moiraes Fate | Office | 0 | 05-18-2007 12:22 PM |
Looping though Custom Properties in VBA | suekay | Misc | 0 | 05-19-2006 06:10 AM |
Visio - Custom Properties Timeout? | googull | Visio | 0 | 05-17-2006 07:37 AM |
setting rules | isapaine | Misc | 0 | 01-11-2006 07:51 AM |