Hi NAS,
Here is a subroutine that works in Access 2003, with Outlook 2003 running:
Option Compare Database
Option Explicit
Sub CountMailMessagesInOutlookFolder()
On Error GoTo ProcError
Dim appOutlook As Outlook.Application
Dim nms As Outlook.NameSpace
Dim fld As Outlook.MAPIFolder
Dim lngItemCount As Long
'--Determine whether Outlook is running
Set appOutlook = GetObject(, "Outlook.Application")
'--Let the user select an Outlook folder to process
Set nms = appOutlook.GetNamespace("MAPI")
Set fld = nms.PickFolder
If fld Is Nothing Then
GoTo ExitProc
End If
If fld.DefaultItemType <> olMailItem Then
MsgBox "The " & fld & " folder does not contain mail messages.", _
vbCritical, "No messages available..."
GoTo ExitProc
End If
lngItemCount = fld.Items.Count
' Debug.Print "Number of messages in folder: " & lngItemCount
MsgBox "There are " & lngItemCount & " messages in the " _
& fld.Name & " folder.", _
vbInformation, "E-Mail Message Count..."
ExitProc:
Set fld = Nothing
Set nms = Nothing
Set appOutlook = Nothing
Exit Sub
ProcError:
Select Case Err.Number
Case 429
MsgBox "Outlook is not running", vbCritical, "Please Start
Outlook First..."
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure
CountMailMessagesInOutlookFolder..."
End Select
Resume ExitProc
End Sub
Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________