Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Location
    Peterborough, UK
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Iterating through folders (Outlook 2K / Object model)

    I've tried to work this out, but have failed miserably :-( Using VB6.

    I have the Namespace as the current object.

    I want to interate through all folders "hanging off" that namespace including subfolders of folders that hold contact details.

    I've kludged around it for the moment by using Pickfolder, but I really only want to display Contact folders.

    Suggestions, code snippets or pointers to useful code would be much appreciated.

    Thanks.

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Iterating through folders (Outlook 2K / Object model)

    Hi Ian,
    I would suggest that you need to use a For Each fdrTemp in Namespace.Folders syntax, and check the fdrTemp.DefaultItemType property. You will also either need to determine how many levels you want to check down and fix that in your code, or create a recursive routine that calls itself if fdrTemp.Folders.Count > 0.
    Hope that gets you started.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    New Lounger
    Join Date
    Mar 2002
    Location
    Peterborough, UK
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Iterating through folders (Outlook 2K / Object model)

    That's what I've been trying to do.

    I found a piece of code on the MSDN site and am calling it as follows:

    Public olkApplication As Object
    Public olkNamespace As Object
    Public olkContactFolder As Object
    Public olkFolder As Object
    Public olkContact As Object
    Public olkMailItem As Object

    Set olkApplication = CreateObject("Outlook.Application")
    Set olkNamespace = olkApplication.GetNamespace("MAPI")
    Set olkFolder = olkNamespace.GetDefaultFolder(olFolderContacts) (I know this isn't iterating yet :-))

    GetFolderInfo (olkFolder)

    where GetFolderInfo is defined as:

    Sub GetFolderInfo(fldFolder as Object)

    When I run the code it bombs on the call to GetFolderInfo with a 424 Object Required.

    Any ideas?

    Puzzled of Peterborough......

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Iterating through folders (Outlook 2K / Object model)

    Instead of developing (debug, debug, code, debug, debug,
    code) with Object as your object, turn on the reference
    library so you get the benefit of the object model at your
    fingertips. Plus, you get the defined constants. Otherwise
    you'll use

    olFolderContacts

    and your app will not have any idea what you are referring to.

    That, I suspect, is your problem. One of them, anyway.
    If you don't reference the library, you'll have to use the index
    number for "olFolderContacts" which I think is 10.

    In your case, it's the Microsoft Outlook 9 Object Library.

    Here's some helpful code:

    #Const mDeveloping = False
    #If mDeveloping Then
    Dim objOutlook As Outlook.Application
    Dim objNameSpace As Outlook.NameSpace
    Dim objOutbox As Outlook.MAPIFolder
    Dim objNewMessage As Outlook.MailItem
    #Else
    Dim objOutlook As Object
    Dim objNameSpace As Object
    Dim objOutbox As Object
    Dim objNewMessage As Object
    #End If
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    New Lounger
    Join Date
    Mar 2002
    Location
    Peterborough, UK
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Iterating through folders (Outlook 2K / Object model)

    Nope, that's not the problem. I have the Object Library turned on and use it extensively.

    I have tried using outlook.whatever in my object definitions and it makes no difference to the problem I am experiencing with this error, hence me moving to the more generic Object to see whether too tight a typecasting (if that's what it can be called here) was the problem.

    It's defined as an an outlook.mapifolder and AFAIK the Mailbox folder is a MAPIFolder, but it still fails with this stoopid message......

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Iterating through folders (Outlook 2K / Object model)

    Post text deleted. It didn't help any after all.

    Still looking for solution. Sorry.
    Attached Images Attached Images
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Iterating through folders (Outlook 2K / Object model)

    How about this: syntax inconsistency.

    Try either:

    Call GetFolder(olkFolder)

    OR

    GetFolder olkFolder
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  8. #8
    New Lounger
    Join Date
    Mar 2002
    Location
    Peterborough, UK
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Iterating through folders (Outlook 2K / Object model)

    That was it!!!!

    Yo!

    Thanks very much. I knew it had to be something stupid.

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Iterating through folders (Outlook 2K / Object model)

    Although it seems incredibly stupid, and sometimes it is wrong in the documentation, it is very important not to use parentheses in Case A, while you must use them in Case B:

    Case A
    ProcedureName object

    Case B
    returnVal = ProcedureName(object)

    Using (object) in Case A evaluates the object to a value before passing it to the procedure. It also evaluates anything else

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •