Creating folders under Personal Folders 
Author Message
 Creating folders under Personal Folders

Hi,

I am trying to write a system that automatically archives data emails
after it processes the information in them, and am trying to add some
code that will create the archive folder trees if they don't already
exist.  I drop thru a folder tree checking if it exists, but if it
gets to a level that doesn't exist, the add statement for that folder
is failing.  If anyone could check my code and tell me what the silly
bit is I'm doing it would be great.

Thanks,
Dave

   Dim objApp As Application
    Dim objNS As NameSpace
    Dim objFolder As MAPIFolder
    Dim TempFolders As MAPIFolder
    Dim objFolders  As Folders
    Dim strName As String
    Dim arrName() As String
    Dim objExpl As Explorer
    Dim I As Integer
    Dim LevelFound As Boolean

    Set objApp = CreateObject("Outlook.Application")
    Set objNS = objApp.GetNamespace("MAPI")

    strName = "Personal Folders/Email Forms/" & _
              "Response Emails"
    arrName = Split(strName, "/")
    Set objFolders = objNS.Folders
    LevelFound = False

    For I = 0 To UBound(arrName)
        For Each objFolder In objFolders
            If objFolder.Name = arrName(I) Then
                'Next Level exists - exit loop
                Set objFolders = objFolder.Folders
                LevelFound = True
                Exit For
            End If
        Next
        If LevelFound = False Then

        'THE CREATE FAILS HERE IF IT CAN'T FIND THE LEVEL !!
        'THE CREATE FAILS HERE IF IT CAN'T FIND THE LEVEL !!
            'Set objTempFolder = objFolders
            'Set myFolder =
olNamespace.GetDefaultFolder(olFolderContacts)
            Set TempFolders = objFolders.Folders.Add(arrName(I))

        End If
        LevelFound = False
    Next

    Set objApp = Nothing
    Set objNS = Nothing
    Set objFolder = Nothing
    Set objFolders = Nothing
    Set objExpl = Nothing



Thu, 08 Jul 2004 20:38:34 GMT  
 Creating folders under Personal Folders
Dave,

When your code finds \\Personal Folders\Email Forms, it sets objFolders
equal to the collection of folders within that folder.  If there are no
subfolders under "Email Forms", this is an empty collection.

Your 'Set TempFolders' statement is trying to add a subfolder at the next
level BELOW this empty collection.  I think you'll get the results you
expect if you change it to

Set TempFolders = objFolders.Add(arrName(I))

DCB


| Hi,
|
| I am trying to write a system that automatically archives data emails
| after it processes the information in them, and am trying to add some
| code that will create the archive folder trees if they don't already
| exist.  I drop thru a folder tree checking if it exists, but if it
| gets to a level that doesn't exist, the add statement for that folder
| is failing.  If anyone could check my code and tell me what the silly
| bit is I'm doing it would be great.
|
| Thanks,
| Dave
|
|    Dim objApp As Application
|     Dim objNS As NameSpace
|     Dim objFolder As MAPIFolder
|     Dim TempFolders As MAPIFolder
|     Dim objFolders  As Folders
|     Dim strName As String
|     Dim arrName() As String
|     Dim objExpl As Explorer
|     Dim I As Integer
|     Dim LevelFound As Boolean
|
|
|     Set objApp = CreateObject("Outlook.Application")
|     Set objNS = objApp.GetNamespace("MAPI")
|
|     strName = "Personal Folders/Email Forms/" & _
|               "Response Emails"
|     arrName = Split(strName, "/")
|     Set objFolders = objNS.Folders
|     LevelFound = False
|
|     For I = 0 To UBound(arrName)
|         For Each objFolder In objFolders
|             If objFolder.Name = arrName(I) Then
|                 'Next Level exists - exit loop
|                 Set objFolders = objFolder.Folders
|                 LevelFound = True
|                 Exit For
|             End If
|         Next
|         If LevelFound = False Then
|
| 'THE CREATE FAILS HERE IF IT CAN'T FIND THE LEVEL !!
| 'THE CREATE FAILS HERE IF IT CAN'T FIND THE LEVEL !!
|             'Set objTempFolder = objFolders
|             'Set myFolder =
| olNamespace.GetDefaultFolder(olFolderContacts)
|             Set TempFolders = objFolders.Folders.Add(arrName(I))
|
|         End If
|         LevelFound = False
|     Next
|
|     Set objApp = Nothing
|     Set objNS = Nothing
|     Set objFolder = Nothing
|     Set objFolders = Nothing
|     Set objExpl = Nothing



Thu, 08 Jul 2004 22:04:16 GMT  
 Creating folders under Personal Folders
Thanks Donald !!

That got it going : )

Dave

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Fri, 09 Jul 2004 05:07:08 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Exchange folder clashes with personal folder

2. Unread Items in Public Folders like in personal Folders

3. Creating Folder and Tasks in Folder

4. Programmatically creating multiple folders in a folder

5. create a folder or find default temp folder

6. Create new folder in current folder in explorer window

7. folder browsing - create folder problem

8. Check for a Folder or Create a New Folder from within vb

9. folder in a folder in a folder...

10. Build XML of folders, sub folders and files from specified folder

11. Determining if a folder is a local pst folder or a imap (server folder)

12. How to delete folders/files within a folder but not the folder itself

 

 
Powered by phpBB® Forum Software