A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Search Folders and VBA



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 14th 06, 09:38 PM posted to microsoft.public.outlook.program_vba
Zip90
external usenet poster
 
Posts: 3
Default Search Folders and VBA

My issue is that I am planning on rolling out an archive solution and
would like to use the search folders to identify all messages that are
about to be deleted by the retention plan to give the users an
opportunity to move them to the archive. For Example "Before 2000"

Lets start with the good news!!

I was able to not only programmatically create the search folders I
need but also change the view to show the total number of items instead
of the unread number.

I know I cannot edit the folder but must delete and recreate.

This can only be done with CDO or Extended Mapi.

I found an example of a CDO function that looks up the ID by name, but
when I use it it only cycles through the visible folders.

I STILL CANNOT FIND THE ID OF THE SEARCH FOLDER.

I think that I need a CDO funtion that will search HIDDEN folders for
the ID of the search folder by name.

Any help would be apreciated.

  #2  
Old November 14th 06, 09:55 PM posted to microsoft.public.outlook.program_vba
Zip90
external usenet poster
 
Posts: 3
Default Search Folders and VBA

Sample CDO function I found that searches for folder by name:

Public Function GetFolderByName( _
ByVal CdoSession As MAPI.Session, _
ByVal strFolderName As String, _
Optional ByVal CdoFolderParent As MAPI.Folder = Nothing, _
Optional ByVal bCreate As Boolean = True _
) As MAPI.Folder

Dim CdoInfoStore As MAPI.InfoStore
Dim CdoFolderRoot As MAPI.Folder
Dim CdoFolders As MAPI.Folders
Dim CdoFolder As MAPI.Folder
Dim bFound As Boolean

' If the parent folder wasn't passed in, then use the root
' folder of the default InfoStore.

If CdoFolderParent Is Nothing Then
' Get the Folders collection from the default InfoStore.
Set CdoInfoStore = CdoSession.GetInfoStore
Set CdoFolderRoot = CdoInfoStore.RootFolder
Set CdoFolders = CdoFolderRoot.Folders
Else
' Get the Folders collection from the parent folder.
Set CdoFolders = CdoFolderParent.Folders
End If

' Loop through the folders in the collection until the
' desired folder is found.
bFound = False
Set CdoFolder = CdoFolders.GetFirst
Do While (Not bFound) And Not (CdoFolder Is Nothing)
If CdoFolder.Name = strFolderName Then
bFound = True
Else
Set CdoFolder = CdoFolders.GetNext
End If
Loop

' If not found, then create it (if caller said to).
If (CdoFolder Is Nothing) And bCreate Then
Set CdoFolder = CdoFolders.Add(strFolderName)
End If

Set GetFolderByName = CdoFolder

' Release our local objects.
Set CdoFolder = Nothing
Set CdoFolders = Nothing
Set CdoFolderRoot = Nothing
Set CdoInfoStore = Nothing

End Function ' GetFolderByName




Does not show Hidden Folders!!

  #3  
Old November 14th 06, 11:44 PM posted to microsoft.public.outlook.program_vba
Zip90
external usenet poster
 
Posts: 3
Default Search Folders and VBA

After 4 days of searching!!!

Here is the function that gets the emtryid:


Function FindSearchFolder(MySession As Session, MyStore As String,
myFolder As String)
Dim cdo As MAPI.Session
Dim store As MAPI.InfoStore
Dim sfld As MAPI.Folder
Dim fld As MAPI.Folder
Dim f As MAPI.Field
Dim strFinderID As String
Dim strList As String
Dim count As Integer
Const PR_FINDER_ENTRYID = &H35E70102
Const PR_IPM_PUBLIC_FOLDERS_ENTRYID = &H66310102
Dim blnMayHaveSearches As Boolean

On Error Resume Next

Set cdo = CreateObject("MAPI.Session")
cdo.Logon "", "", False, False

Set store = cdo.GetInfoStore(MyStore)
strFolderName = UCase(myFolder)
blnMayHaveSearches = True

' ignore if it's the Public Folders hierarchy
' don't have search folders in Public Folders
If store.ProviderName = "Microsoft Exchange Server" Then
Set f = store.Fields.Item(PR_IPM_PUBLIC_FOLDERS_ENTRYID)
If Not f Is Nothing Then
blnMayHaveSearches = False
End If
Set f = Nothing
End If

If blnMayHaveSearches Then
strFinderID = _
store.Fields.Item(PR_FINDER_ENTRYID).Value
Set sfld = cdo.GetFolder(strFinderID, store.ID)
If Not sfld Is Nothing Then
count = sfld.Folders.count
If count 0 Then
strList = strList & vbCrLf & store.Name & " has " &
_
CStr(count) & " search " & _
IIf(count = 1, "folder:", "folders:")
For Each fld In sfld.Folders
If fld.Name = myFolder Then
FindSearchFolder = fld.ID

Exit Function
End If
Next
strList = strList & vbCrLf
End If
End If

End If

If Len(strList) 2 Then
strList = Mid(strList, 3)
FindSearchFolder = Null
Else
MsgBox "No search folders found"
FindSearchFolder = Null

End If

cdo.Logoff
Set cdo = Nothing
Set store = Nothing
Set fld = Nothing
Set sfld = Nothing
End Function

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Search in sub-folders in Public Folders Nicolas Macarez Outlook - General Queries 3 November 9th 06 10:46 AM
Search folders do not update Oren Yulevitch Outlook - General Queries 0 October 22nd 06 12:50 PM
accessing search folders Al Shannon Outlook and VBA 1 July 13th 06 04:04 PM
How to open Public Folders 'Contact Form' using VBA mmattson Outlook and VBA 1 May 17th 06 11:06 PM
Hide/Delete Deleted Items & Search Folders Folders in Outlook 2003 jpspringall Outlook and VBA 1 April 24th 06 03:51 PM


All times are GMT +1. The time now is 08:26 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.