Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Refering to Inbox subfolders in VB

Posted on 2003-03-05
9
Medium Priority
?
444 Views
Last Modified: 2010-04-07
I currently have a program that checks Outlook 2000 every 60 seconds for new emails that have Attachments with a specific naming convention, when found the Attachment is copied to an external directory for pickup by a Mainframe program. The actioned email is then moved to a subfolder of Inbox, in Outlook 2000. Currently there is only 1 subfolder so I can get away with refering to this subfolder as follows:

Set oSubFolder = oFolder.Folders.Item(1)

Thus using oSubFolder whenever I mean the subfolder.

My challenge: they want to add ~50 new subfolders now and some more later.

My Question: Is there a way to refer to a subfolder by name rather than by item number, as the relative position of subfolders is probably going to change with each set of additions and probably deletions.

Thanks,
vbmds
0
Comment
Question by:vbmds
  • 4
  • 3
  • 2
9 Comments
 
LVL 16

Accepted Solution

by:
Neo_mvps earned 600 total points
ID: 8077555
Yes, the item method accepts a number or name of folder as an arguement.  The only thing they/you have to keep in mind is that each folder name under Inbox is unique.
0
 

Author Comment

by:vbmds
ID: 8078004
Thanks Neo_mvps, this confirms what my books and online documentation hint at. Unfortunately thats all they do, and thus do not give any sort of example to play around with.

Anyway this gives me a starting point,

Thanks,
vbmds
0
 
LVL 6

Expert Comment

by:DominicCronin
ID: 8094543
Just wondering about the need for polling each minute. You can subscribe to an event when the mail arrives, so wouldn't this be better

Private WithEvents gFolInboxItems As Outlook.Items

Private Sub Application_Startup()
    Set gFolInboxItems = Application.GetNamespace( _
                                "MAPI").GetDefaultFolder(olFolderInbox).Items
   
End Sub

Private Sub gFolInboxItems_ItemAdd(ByVal Item As Object)

    Dim lMailItem As Outlook.MailItem
    If Item.Class = olMail Then
        Set lMailItem = Item
    Else
        ' We're only interested in Mails
        Exit Sub
    End If

    Dim theAttachment As Attachment
    For Each theAttachment In lMailItem.Attachments
        If MatchesNamingConvention(theAttachment.FileName) Then
            ' Do your stuff
        End If
    Next

End Sub
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:vbmds
ID: 8099242
DominicCronin,

Thanks. That is a little more straightforward than what I've done. However, this has been my first time programming to Outlook, and given the fact that the project was a emergency short term stop gap measure I didn't have much time to learn about Outlook, about 12 months ago.  If I get to rewrite the program I will certainly look to make use of your suggestion.

So, thanks again for your input.

vbmds
0
 
LVL 6

Expert Comment

by:DominicCronin
ID: 8105116
I know what you mean - Outlook is very poorly documented. I don't do much Office programming, but I have to say that it's harder than it should be. For example, the VBA help that ships with Office XP (which is what I'm using) seems to refer to Office 2002, and the examples don't seem to work with the Object model I can see!!!

Anyway - what the heck is an Explorer, or an Inspector, or whatever? How do these things map to the stuff you see in the user interface. Rant, rave, spit, scream, stamp etc.
0
 
LVL 16

Expert Comment

by:Neo_mvps
ID: 8105280
Explorer = Main Outlook window that shows a folder

Inspector = Window that is displaying an item. (Note: Inspector can behave oddly when Word is enabled as your editor.)

FWIW, Look for a book by Sue Mosher (owner/operator of http://www.slipstick.com).  She is probably one of the best writers that I have seen for beginning to intermediate users that want to work with the Outlook Object Model.
0
 

Author Comment

by:vbmds
ID: 8107491
I have to say that much of the code source I use for my Office work starts life as code snipits by Sue Mosher and other contributors to Slipstick.com. Other than this site, Slapstick.com is the most valuable resource.

DominicCronin, luckily for me I only have to work with Office97 and Office2000. I really dislike VBA for Office work, its like coding HTML in notepad, you don't get any real-time feedback and when you have 10K lines of the stuff its a nightmare!

While I have both your attention a small question: the outlook program is up and running but I have found that a For Each Next statement that is supposed to process each email in the Inbox dumps out after about 50% done and appears to have lost/forgot what collection it is supposed to be processing the items from. It does not make too much impact as the program picks up where it left off next iteration, it just a bit puzzeling.
0
 
LVL 6

Expert Comment

by:DominicCronin
ID: 8113583
Thanks for the hints from both of you. I'll definitely have a look at slipstick.

Meanwhile, vbmds, can you post a code snippet illustrating your problem? Are you working in Vb or VBA? If the former, then I guess you could try to set the debugger up to break on all errors to see if there's any more info to be had. (I don't know if that's possible in VBA)
0
 

Author Comment

by:vbmds
ID: 8115050
I'm using VB. There does not appear to be any errors, it just forgets what its doing. I probably should kick off another question with some points.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
Often, the users face difficulty in accessing Outlook 2016 PST files on Windows 10 computer. One of the reasons behind it is the improper functioning of MS Outlook when the user tries to open it. MS Outlook suddenly stops working, or it will not op…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question