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 - email@example.com").Folders("Sent Items")
If Err.Number <> 0 Then
MsgBox "No such folder."
EmailCount = objFolder.Items.Count
MsgBox "Number of emails in the folder: " & EmailCount, , "email count"