Link to home
Start Free TrialLog in
Avatar of jonlake
jonlakeFlag for Guernsey

asked on

Count items in MS Outlook Outbox

Hi, I am trying to use VBA from within MS Access to count the number of items sitting in a users MS Outlook outbox. The challenge is that the user default folder name is going to be different from user to user. So, what I need is for the VBA to find the default folder name and the pass it into the code. Here is what I have (currently counting sent items), which works when specifying the name:

    Dim objOutlook As Object, objnSpace As Object, objFolder As MAPIFolder
    Dim EmailCount As Integer
    Set objOutlook = CreateObject("Outlook.Application")
    Set objnSpace = objOutlook.GetNamespace("MAPI")

        On Error Resume Next
        Set objFolder = objnSpace.Folders("Google Apps - bob.smith@emailbox.com").Folders("Sent Items")
        If Err.Number <> 0 Then
        Err.Clear
        MsgBox "No such folder."
        Exit Sub
        End If

    EmailCount = objFolder.Items.Count

    MsgBox "Number of emails in the folder: " & EmailCount, , "email count"
ASKER CERTIFIED SOLUTION
Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jonlake

ASKER

Perfect, thank you very much