Hi Guys
I have had a stab at this and i seem to fall over ..
Is there a way (VBA) to change the default outlook profile from 1 (default) to 2 -
I can send an email and get Access 2010 to know which account to send from
but after I have sent an email the D/b then checks sent items and copies the email into a folder ( refernced accordingly)
However - it only searches the "default" sent folder - 1
so my logic is -keep it simple change the default profle at the start of the process and then change back to true default profile (1) at the end
(I have posted stuff on this before - but I think I have over complicated it )
With mi
.To = Nz(Me.email)
.Subject = Subjectz
.HTMLBody = Me.emailrichtxt & bqe & bqe & "." & Signature
.Categories = ID
If Me.EU = True Then
.SendUsingAccount = ol.Session.Accounts(2)
End If
If Me.EU = False Then
.SendUsingAccount = ol.Session.Accounts(1)
End If
******* the above works
***** the below always checks the true default sent box - not the one I want it to
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 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
End Function
I have had a stab at this and i seem to fall over ..
Is there a way (VBA) to change the default outlook profile from 1 (default) to 2 -
I can send an email and get Access 2010 to know which account to send from
but after I have sent an email the D/b then checks sent items and copies the email into a folder ( refernced accordingly)
However - it only searches the "default" sent folder - 1
so my logic is -keep it simple change the default profle at the start of the process and then change back to true default profile (1) at the end
(I have posted stuff on this before - but I think I have over complicated it )
With mi
.To = Nz(Me.email)
.Subject = Subjectz
.HTMLBody = Me.emailrichtxt & bqe & bqe & "." & Signature
.Categories = ID
If Me.EU = True Then
.SendUsingAccount = ol.Session.Accounts(2)
End If
If Me.EU = False Then
.SendUsingAccount = ol.Session.Accounts(1)
End If
******* the above works
***** the below always checks the true default sent box - not the one I want it to
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 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
End Function