HOWTO: Remove Published Forms from a Folder Using CDO
ID: Q200176
|
The information in this article applies to:
-
Collaboration Data Objects (CDO), versions 1.2, 1.21
SUMMARY
Forms are added to folders frequently. It may be necessary from time to time to remove some or all of the forms from a particular folder. The following sample code uses Collaboration Data Objects (CDO) Library in a Microsoft Visual Basic project to locate and potentially remove any or all of the forms installed in a given folder. It uses CDO to access the HiddenMessages collection of the folder, report the DisplayName of each and delete Form Definition Messages (FDMs) from that collection.
MORE INFORMATION
A Form Definition Message (FDM) has a message class of the following:
IPM.Microsoft.FolderDesign.FormsDescription
These messages are stored in the HiddenMessages collection of a folder. The messages in the HiddenMessages collection are not visible through the Microsoft Exchange Client, Microsoft Outlook, or Microsoft Outlook Web Access (OWA). These hidden messages correspond to the folder associated information kept in a folder by MAPI.
Some messaging clients use hidden messages to accomplish special tasks, for example, the processing of rules by the Microsoft Exchange Client's Inbox Assistant or View Descriptor messages for views that are defined within a particular folder are stored.
Please note that you should leave the HiddenMessages collection unchanged unless you are familiar with the consequences of any modifications you might make.
Sample Code
Option Explicit
'
'The FindFolder function searches for the first instance of a folder
'with the DisplayName <strName> in the folders collection <objFolders>.
'This can take a considerable amount of time depending on the
'complexity of the folder hierarchy.
'
Function FindFolder(ByVal strName As String, _
objFolders As MAPI.Folders) As MAPI.Folder
Dim objTmp As MAPI.Folder
Dim objTarget As MAPI.Folder
For Each objTmp In objFolders
If InStr(1, objTmp.Name, strName, vbTextCompare) > 0 Then
Set objTarget = objTmp
Exit For
End If
Next
If objTarget Is Nothing Then
For Each objTmp In objFolders
Set objTarget = FindFolder(strName, objTmp.Folders)
If Not objTarget Is Nothing Then Exit For
Next
End If
Set FindFolder = objTarget
End Function
Private Sub Command1_Click()
Dim objSession As New MAPI.Session
Dim objFolders As MAPI.Folders
Dim objFolder As MAPI.Folder
Dim objHiddenMessages As MAPI.Messages
Dim objFDMMessage As MAPI.Message
'Logon to the Session
objSession.Logon
'GetInfoStore("") returns the default InfoStore object
Set objFolders = objSession.GetInfoStore("").RootFolder.Folders
'Locate the target folder
'TODO: Change TARGET_FOLDER to the name of your target folder
Set objFolder = FindFolder("TARGET_FOLDER", objFolders)
'If we cannot find target folder, complain and leave
If objFolder Is Nothing Then
MsgBox "Cannot locate requested folder"
GoTo Finished:
End If
'We found the folder, so delete the FDM messages
'Get the HiddenMessages collection
Set objHiddenMessages = objFolder.HiddenMessages
'Find the first FDM
Set objFDMMessage = objHiddenMessages.GetFirst( _
"IPM.Microsoft.FolderDesign.FormsDescription")
While Not objFDMMessage Is Nothing 'If we found an FDM
'Report the FDM's DisplayName and ask if it is to be deleted
If MsgBox(objFDMMessage.Fields(CdoPR_DISPLAY_NAME), vbYesNo, _
"Delete this form from " & objFolder.Name & "?") = vbYes Then
'If yes then delete
objFDMMessage.Delete
End If
'Now look for the next FDM
Set objFDMMessage = objHiddenMessages.GetNext
Wend
'All done
MsgBox "That's all, folks!"
Finished:
'Log off and cleanup
objSession.Logoff
Set objSession = Nothing
Unload Me
End Sub
REFERENCES
MSDN: Microsoft Collaboration Data Objects Programmer's Reference Cdo.hlp (Version 1.21)
Additional query words:
kbCode kbMsg kbCDO120 kbCDO121 kbcdo
Keywords : kbCDO120 kbCDO121 kbMsg kbVBp kbGrpMsg
Version : WINDOWS:1.2,1.21
Platform : WINDOWS
Issue type : kbhowto