Access 2016 Send Attachment SentOnBehalfOfName

Mac1206

Board Regular
Joined
Jun 3, 2016
Messages
184
Hello,

I'm trying to use the SentOnBehalfOfName in order to mask the default user email name with our shared group email name. I have SendAs permissions but when I click on the email send button, I still see my default user email and not the "GroupUser@Test.com" test example email. My code does not error out but something is wrong. Could you please have a look and help me out with this: I added this 4 Dim's and following highlighted code for the SentOnBehalfOfName...



Private Sub CmdEmailRpt_Click()

Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim strSql As String
Dim strTo As String
Dim txtID As TempVars

Dim OutApp As Outlook.Application
Dim objOutlookTo As Outlook.MailItem
Dim objOutlookRecip As Recipient
Dim Recipients As Recipients



Set db = CurrentDb()

strSql = "Select * FROM Qry_Max_Pymt_PymtEmailDetail;"


Set rst = CurrentDb.OpenRecordset(strSql)

Set OutApp = CreateObject("Outlook.Application")
Set objOutlookTo = OutApp.CreateItem(olMailItem)


Set Recipients = objOutlookTo.Recipients
Set objOutlookRecip = Recipients.Add("GroupUser@Test.com")
objOutlookRecip.Type = 1

objOutlookTo.SentOnBehalfOfName = "GroupUser@Test.com"


'Resolve each Recipient's name.
For Each objOutlookRecip In objOutlookTo.Recipients
objOutlookRecip.Resolve

Next


With rst

Do While Not rst.EOF

strTo = !Email & ";"

TempVars("txtID") = rst!ID.Value

DoCmd.SendObject acSendQuery, "Max_Pymt_EmailDetails1", acFormatXLS, strTo, , "EmailTest@Test.com", "TestDetails - Test", "Greetings. Please find the attached payment detail for the payment released today from the Custodian. If you have any questions or would like additional information please contact Test@AnotherTest.com." & vbCrLf & vbCrLf, False

DoEvents
rst.MoveNext

Loop

End With

rst.Close

Set rst = Nothing
Set db = Nothing

End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I shorten the code to this:


Private Sub CmdEmailRpt_Click()



Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim strSql As String
Dim strTo As String
Dim txtID As TempVars

Dim OutApp As Outlook.Application
Dim objOutlookTo As Outlook.MailItem


Set db = CurrentDb()

strSql = "Select * FROM Qry_Max_Pymt_PymtEmailDetail;"

Set rst = CurrentDb.OpenRecordset(strSql)

Set OutApp = CreateObject("Outlook.Application")
Set objOutlookTo = OutApp.CreateItem(olMailItem)

objOutlookTo.SentOnBehalfOfName = "GroupUser@Test.com"


With rst

Do While Not rst.EOF

strTo = !Email & ";"

TempVars("txtID") = rst!ID.Value

DoCmd.SendObject acSendQuery, "Max_Pymt_EmailDetails1", acFormatXLS, strTo, , "EmailTest@Test.com", "TestDetails - Test", "Greetings. Please find the attached payment detail for the payment released today from the Custodian. If you have any questions or would like additional information please contact Test@AnotherTest.com." & vbCrLf & vbCrLf, False

DoEvents
rst.MoveNext

Loop

End With

rst.Close

Set rst = Nothing
Set db = Nothing


End Sub
 
Upvote 0
You would need to Send from within Outlook for it to work, not from Access.?
 
Upvote 0
Thanks for the response Welshgasman,

Could you please elaborate more on your above statement, I don't understand where you going with this, thanks...
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top