outlook email count

  • Thread starter Thread starter NAS
  • Start date Start date
N

NAS

Is there any way to create a query that will tell you how many emails are in
a certain mailbox? For example, if there are 5 emails in my inbox, can I make
a query that will reflect this?
 
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/
__________________________________________
 
PS.
I forgot to mention that the code, as written, requires a checked reference
to the "Microsoft Outlook {version} Object Library", where {version} = 11.0
for Outlook 2003. You can further refine the code to use late binding (ie. no
checked version specific reference needed).


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
 
outlook mail count

hi Tom Wickerath..

i used your solution but i need your help for something else.. can u plz help me..

what i want to do is that i have a mailbox and i want to count all the mails that drop in that mailbox during the day..

for example..
1. i got a mailbox named xxx where mails drop in from a website automatically.
2. the mails are moved manually to other mailbox aaa from xxx.
3. therefore at the end of the day i want to know how many mails drop in xxx

can you please help me with the codes..

my email address is: (e-mail address removed)

waiting for your reply.. thank you...
 
Last edited:
Back
Top