View Single Post
 
Old 05-10-2021, 02:03 AM
GaryPanic GaryPanic is offline Windows 10 Office 2010
Novice
 
Join Date: May 2021
Posts: 1
GaryPanic is on a distinguished road
Default Is there an alternative to "GetDefaultFolder"

Hello - first time posting in this forum (I have an MS Access account same name etc)
I have raised this in the access forum - but its is more an Outlook rather than Access question



I have a little bit of coding (I have edited tot he problem element)

basically it looks int he sent items - sees the email that has been referenenced and copies /renames it into a network folder - works a dream - until .....


If I have two Outlook accounts (I do - ) it only checks the "default" sent items and never the alternative one - even though i send from the alternaive



Effectively what i am looking for is an alternative to getdefaultfolder (sent) to

get sent folder from either account no 1 or account no 2 (or check all "sent" folders code below



not bothered if it checks both sent folders - but i am stuck on this



- coding is not mine - #i have hacked it to suit purpose



( With olkns.GetDefaultFolder(olFolderSentMail))








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





Private Sub Command188_Click()
'DoCmd.SetWarnings False
DoCmd.OpenQuery "QuoteemptyemailtxtQry", acViewNormal, acEdit
Me.RecZlocked = -1

'DoCmd.SetWarnings True


DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close
'QuoteemptyemailtxtQry

End Sub
Reply With Quote