changing outlook GetDefaultFolder(olFolderSentMail) (1 Viewer)

GaryPanic

Smoke me a Kipper,Skipper
Local time
Yesterday, 23:11
Joined
Nov 8, 2005
Messages
3,296
Hi Guys
I am sure this is a quickie
I am passing through from access to outlook ( I can get it to send from default and also send from an alterntive account (2)
but the filing system looks at the default "get Default" how do I get it to look at the sent account (2) profile ??




Dim olkns As Outlook.NameSpace

Dim items As Outlook.items
Dim item As Object
Dim attempt As Integer
Set olkapp = Outlook.Application
'###



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
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:11
Joined
Oct 29, 2018
Messages
21,358
You can use MAPI.Namespace. Let me see if I can find a link for you...

Edit: Okay, hope this helps a bit...

Edit2: Hmm, after re-reading your post I am not sure what I posted would be enough information to find your solution. I am now thinking you'll need a combination of Accounts and Sessions to get the folder from the second account.
 
Last edited:

GaryPanic

Smoke me a Kipper,Skipper
Local time
Yesterday, 23:11
Joined
Nov 8, 2005
Messages
3,296
would this not work ?
Set OlkSess = Application.session(2) ???
 

Isaac

Lifelong Learner
Local time
Yesterday, 23:11
Joined
Mar 14, 2017
Messages
8,738
An alternative approach would be to set up an additional Mail profile on your computer. In this profile, only reference the account (that you wish to use in this project). Then, open Outlook (it will prompt you for a profile), and run your same code.
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Yesterday, 23:11
Joined
Nov 8, 2005
Messages
3,296
Hmm - this one has me stumped##

thought it would be easy just to set the reference but ..
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Yesterday, 23:11
Joined
Nov 8, 2005
Messages
3,296
OK I found this and I presume that I can edit Inputfolder refernce the sentfolder?


Dim olNS As NameSpace
Dim InputFolder As Outlook.MAPIFolder
Set olNS = Outlook.Application.GetNamespace("MAPI")

' Get reference to folder in users Mailbox for Input
Set InputFolder = olNS.Folders("Procurement, Request").Folders("Inbox")

' all the emails in the shared inbox are represented by:
InputFolder.Items

and edit " With olkns.GetDefaultFolder(olFolderSentMail)"
 

Users who are viewing this thread

Top Bottom