GaryPanic
New Member
- Outlook version
- Outlook 2010 32 bit
- Email Account
- Outlook.com (as MS Exchange)
Hello- first post ..
I have a bit of VBA that checks my default sent items for an email and file save as into a network folder (within a Access Database )
(works brilliantly not my work )
However I have two accounts
primary and secondary
the check sent items only checks .GetDefaultFolder(olFolderSentMail)
is there another way of getting to check an alternative sent folder ?
( I would be ok with it check default and the alternative at the same time )
(background * I need to split EU and non EU emails - ) when I send them they send from the right account - Primary *non eu and secondary EU and this I ahve filtered but the use of a tick box on my form
Private Function FindSentItem(itemID As String, sentFromTime As Date) As Outlook.MailItem
Const MAX_TRY_COUNT = 3
Const SLEEP_TIME = 1000
Dim olkapp As Outlook.Application
Dim olkns As Outlook.NameSpace
Dim olAcc As Outlook.Account
Dim items As Outlook.items
Dim item As Object
Dim attempt As Integer
Set olkapp = Outlook.Application
'###
'Set olAcc = Outlook.Accounts.Session(2)
Set olkns = olkapp.GetNamespace("MAPI")
attempt = 1
findSentItem_start:
With olkns.GetDefaultFolder(olFolderSentMail)
Set items = .items.Restrict("[SentOn] >= '" & Format(sentFromTime, "ddddd h:nn AMPM") & "'")
For Each item In items
If TypeName(item) = "MailItem" Then
If item.Categories = itemID Then
Set FindSentItem = item
Exit Function
End If
End If
Next item
End With
'
' If not found at this attempt, try again
' after some sleep
'
If attempt < MAX_TRY_COUNT Then
attempt = attempt + 1
' Pause (0.1)is 0.1 second
Pause (3)
'Call Sleep(SLEEP_TIME)
GoTo findSentItem_start
End If
Set FindSentItem = Nothing
End Function
I have a bit of VBA that checks my default sent items for an email and file save as into a network folder (within a Access Database )
(works brilliantly not my work )
However I have two accounts
primary and secondary
the check sent items only checks .GetDefaultFolder(olFolderSentMail)
is there another way of getting to check an alternative sent folder ?
( I would be ok with it check default and the alternative at the same time )
(background * I need to split EU and non EU emails - ) when I send them they send from the right account - Primary *non eu and secondary EU and this I ahve filtered but the use of a tick box on my form
Private Function FindSentItem(itemID As String, sentFromTime As Date) As Outlook.MailItem
Const MAX_TRY_COUNT = 3
Const SLEEP_TIME = 1000
Dim olkapp As Outlook.Application
Dim olkns As Outlook.NameSpace
Dim olAcc As Outlook.Account
Dim items As Outlook.items
Dim item As Object
Dim attempt As Integer
Set olkapp = Outlook.Application
'###
'Set olAcc = Outlook.Accounts.Session(2)
Set olkns = olkapp.GetNamespace("MAPI")
attempt = 1
findSentItem_start:
With olkns.GetDefaultFolder(olFolderSentMail)
Set items = .items.Restrict("[SentOn] >= '" & Format(sentFromTime, "ddddd h:nn AMPM") & "'")
For Each item In items
If TypeName(item) = "MailItem" Then
If item.Categories = itemID Then
Set FindSentItem = item
Exit Function
End If
End If
Next item
End With
'
' If not found at this attempt, try again
' after some sleep
'
If attempt < MAX_TRY_COUNT Then
attempt = attempt + 1
' Pause (0.1)is 0.1 second
Pause (3)
'Call Sleep(SLEEP_TIME)
GoTo findSentItem_start
End If
Set FindSentItem = Nothing
End Function