Alternative to "getfedualtfolder"

Status
Not open for further replies.

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
 
You need to use the get folderpath function and then will call the second sent folder using

Set sFolder = GetFolderPath("account@domain\SentI tems")


So you can loop the code, I would use something like this:

for getAccount = 1 to 2

select case
case 1
Set sFolder = olkns.GetDefaultFolder(olFolderSentMail)
case 2
Set sFolder = GetFolderPath("account@domain\SentI tems")
end select


With SFolder
' rest of code

end with
next



 
I need to put this into action - but I thought it would be simple and if this works - then yes its very simple -
all the other routes I have been "awkward"
 
Worked like a dream - thank you ..
 
Status
Not open for further replies.
Back
Top