johnnyg123
asked on
Read outlook folders from ms access
I have several mailboxes with each mailbox containing a number of folders.
I would like to create an access aplication that can display the number of items in the folders for a given mailbox but not sure how to go about doing that.
The ultimate goal is to create an access report that for a given mail box will list all the folders along with the number of items in the folder (both read and unread).
I have attached a screen shot show an example of one of the mail boxes along with the folders
Thanks!
mailbox-list.doc
I would like to create an access aplication that can display the number of items in the folders for a given mailbox but not sure how to go about doing that.
The ultimate goal is to create an access report that for a given mail box will list all the folders along with the number of items in the folder (both read and unread).
I have attached a screen shot show an example of one of the mail boxes along with the folders
Thanks!
mailbox-list.doc
remove
On Error GoTo err_att
On Error GoTo err_att
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
eghtebas,
I tried the code you posted.
I get a message stating a program is trying to access addresses and if I want to allow.
If I click yes, the form does display a portion of my outlook window but this locks my machine
I tried the code you posted.
I get a message stating a program is trying to access addresses and if I want to allow.
If I click yes, the form does display a portion of my outlook window but this locks my machine
ASKER
irudyk,
I tried the code you posted.
I get an error saying object not found when access executes the following line of code
Set olFolder = olMailbox.Folders("Inbox")
I tried the code you posted.
I get an error saying object not found when access executes the following line of code
Set olFolder = olMailbox.Folders("Inbox")
Hmm, not sure how you could get an error message on that line when just prior to that line I have an On Error Resume Next (i.e. which practically means to ignore any error)?
Have you tried to copy and paste the code in a new/blank database file and run it from there just to rule out that it might be some other issue within your existing database file?
ASKER
jrudyk
Appreciate the suggestion
For some reason it was indeed an issue with my database.
Appreciate the suggestion
For some reason it was indeed an issue with my database.
ASKER
Thanks everyone fro the posts. Between these posts and some other research I did, I managed to piece together the solution I needed. Hope you don't mind that I'm splitting the points
For future reference here is the code:
(Note: The form has a different command button for each mailbox/profile I needed. for space sake I only included the code for one of the command buttons. The attached file shows an example of my mailbox structure and a snippet of the output file)
Option Compare Database
Dim MY_FOLDER
Dim MY_PROFILE
Private Const MY_PROFILE_PASSWORD = Set this to the mailbox password
Dim objCDO
Dim objRootFolder
Dim objFolder
Dim objInfoStore
Dim datTriggerDateNewest
Dim datTriggerDateOldest
Dim intProcessedMessages
Private Sub cmdNEContact_Click()
'Script cycles through all Messages in an Outlook Store
MY_FOLDER = "set this to mailbox name"
MY_PROFILE = "set this to profile name"
Open "C:\NEContactMailInfo.txt" For Output As #1
Set objCDO = CreateObject("MAPI.Session ")
objCDO.Logon MY_PROFILE, MY_PROFILE_PASSWORD
If GetRootFolder(MY_FOLDER) Then
Set objRootFolder = objInfoStore.RootFolder
For Each objFolder In objRootFolder.Folders
ProcessFolder objFolder
Next
End If
objCDO.Logoff
Set objFolder = Nothing
Set objRootFolder = Nothing
Set objInfoStore = Nothing
Set objCDO = Nothing
MsgBox "C:\NEContactMailInfo.txt created."
Close #1
End Sub
Function GetRootFolder(strFolderNam e)
GetRootFolder = False
For Each objInfoStore In objCDO.InfoStores
If objInfoStore.Name = strFolderName Then
GetRootFolder = True
Exit For
End If
Next
End Function
Sub ProcessFolder(objFolder)
Dim objSubFolders
Dim objSubFolder
Dim objMessages
Dim objMessage
Dim arrCategories()
Dim intCatItem
Dim OwnerName
On Error Resume Next
If objFolder.Folders.Count > 0 Then
Set objSubFolders = objFolder.Folders
For Each objSubFolder In objSubFolders
Print #1, vbCrLf & vbCrLf & objFolder.Name & " - Owner# " & objSubFolder.Name & " has " & objSubFolder.Messages.Coun t & " messages" & vbCrLf
'MsgBox (objFolder.Name & " - Owner# " & objSubFolder.Name & " has " & objSubFolder.Messages.Coun t & " messages")
If objSubFolder.Messages.Coun t > 0 Then
Set objMessages = objSubFolder.Messages
For Each objMessage In objMessages
Print #1, " " & objMessage.Subject & " " & objMessage.TimeReceived & vbCrLf
Next
End If
ProcessFolder objSubFolder
Next
End If
Set objFolder = Nothing
Set objSubFolders = Nothing
Set objMessage = Nothing
Set objMessages = Nothing
End Sub
listing.doc
For future reference here is the code:
(Note: The form has a different command button for each mailbox/profile I needed. for space sake I only included the code for one of the command buttons. The attached file shows an example of my mailbox structure and a snippet of the output file)
Option Compare Database
Dim MY_FOLDER
Dim MY_PROFILE
Private Const MY_PROFILE_PASSWORD = Set this to the mailbox password
Dim objCDO
Dim objRootFolder
Dim objFolder
Dim objInfoStore
Dim datTriggerDateNewest
Dim datTriggerDateOldest
Dim intProcessedMessages
Private Sub cmdNEContact_Click()
'Script cycles through all Messages in an Outlook Store
MY_FOLDER = "set this to mailbox name"
MY_PROFILE = "set this to profile name"
Open "C:\NEContactMailInfo.txt"
Set objCDO = CreateObject("MAPI.Session
objCDO.Logon MY_PROFILE, MY_PROFILE_PASSWORD
If GetRootFolder(MY_FOLDER) Then
Set objRootFolder = objInfoStore.RootFolder
For Each objFolder In objRootFolder.Folders
ProcessFolder objFolder
Next
End If
objCDO.Logoff
Set objFolder = Nothing
Set objRootFolder = Nothing
Set objInfoStore = Nothing
Set objCDO = Nothing
MsgBox "C:\NEContactMailInfo.txt created."
Close #1
End Sub
Function GetRootFolder(strFolderNam
GetRootFolder = False
For Each objInfoStore In objCDO.InfoStores
If objInfoStore.Name = strFolderName Then
GetRootFolder = True
Exit For
End If
Next
End Function
Sub ProcessFolder(objFolder)
Dim objSubFolders
Dim objSubFolder
Dim objMessages
Dim objMessage
Dim arrCategories()
Dim intCatItem
Dim OwnerName
On Error Resume Next
If objFolder.Folders.Count > 0 Then
Set objSubFolders = objFolder.Folders
For Each objSubFolder In objSubFolders
Print #1, vbCrLf & vbCrLf & objFolder.Name & " - Owner# " & objSubFolder.Name & " has " & objSubFolder.Messages.Coun
'MsgBox (objFolder.Name & " - Owner# " & objSubFolder.Name & " has " & objSubFolder.Messages.Coun
If objSubFolder.Messages.Coun
Set objMessages = objSubFolder.Messages
For Each objMessage In objMessages
Print #1, " " & objMessage.Subject & " " & objMessage.TimeReceived & vbCrLf
Next
End If
ProcessFolder objSubFolder
Next
End If
Set objFolder = Nothing
Set objSubFolders = Nothing
Set objMessage = Nothing
Set objMessages = Nothing
End Sub
listing.doc
johnnyg123,
Sorry for not being able to get back to you sooner.
re:> I get an error saying object not found when access executes the following line of code
If not added yet, you need to add the following reference:
Microsoft Outlook 11.0 Object Library
Good luck with your project.
Mike
Sorry for not being able to get back to you sooner.
re:> I get an error saying object not found when access executes the following line of code
If not added yet, you need to add the following reference:
Microsoft Outlook 11.0 Object Library
Good luck with your project.
Mike
Compile befor runing it.
Mike
Open in new window