Send Report Through Access Form (1 Viewer)

andrew.abaye

New member
Local time
Today, 17:24
Joined
Jun 22, 2024
Messages
12
Hello Folks,

I have created a form which allows me to print Access Report based on the criteria supplied on the combobox of the form which works fine. I have a second to email the report to the user and I have created a query which have the recipients email addresses. I expect the function to pick the email address of the recipient from the query and send the report. The function lunches outlook with the file in attachement but it does not pick the email address of the user from the file.
Email Report.png

This is the code running on the Email button. I need help please.

Private Sub email_payslip_Click()
On Error Resume Next
Dim stDocName As String
Dim StaffEmail As String
Dim rs As DAO.Recordset
Set rs = db.OpenRecordset("qryemployeeEmail", dbOpenDynaset)
rs.MoveFirst

StaffEmail = rs(email)
stDocName = "EmployeePaySlip"
StaffID = Employeebox
Payserial = Payserialbox
Do
Employeebox = rs(employee_id)
Payserialbox = rs(PaYserialNumber)
'DoCmd.OpenReport stDocName, acPreview
DoCmd.SendObject acSendReport, stDocName, "PDFFormat(*.pdf)", StaffEmail, "", "", "Monthly PaySlip", "Kindly find your Monthly Payslip attached. Thank you.", False

rs.MoveNext
Loop Until rs.EOF
End Sub
 

andrew.abaye

New member
Local time
Today, 17:24
Joined
Jun 22, 2024
Messages
12
Maybe you meant to use?
Code:
StaffEmail = rs("email")
Thanks so much for pointing out an in my code. I have made that correction now. I now have a popup saying a program is trying to send email on your behalf which should be but when I click allow I don't see anything in outbox or in the inbox of the recipient. I have attached my final code and the screenshot here. Please help

Private Sub email_payslip_Click()
On Error Resume Next
Dim stDocName As String
Dim StaffEmail As String
Dim rs As DAO.Recordset
Set rs = db.OpenRecordset("qryemployeeEmail", dbOpenDynaset)
rs.MoveFirst

StaffEmail = rs("email")
stDocName = "EmployeePaySlip"
StaffID = Employeebox
Payserial = Payserialbox
Do
Employeebox = rs(employee_id)
Payserialbox = rs(PaYserialNumber)
'DoCmd.OpenReport stDocName, acPreview
DoCmd.SendObject acSendReport, stDocName, "PDFFormat(*.pdf)", ("email"), "", "", "Monthly PaySlip", "Kindly find your Monthly Payslip attached. Thank you.", False

rs.MoveNext
Loop Until rs.EOF
End Sub
 

Attachments

  • Email popup.png
    Email popup.png
    74.6 KB · Views: 13

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:24
Joined
May 7, 2009
Messages
19,268
i have this answer from ChatGPT:

sent_items.jpg
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:24
Joined
Sep 21, 2011
Messages
14,713
You would be using StaffEmail surely and not "email" which is just a literal and not even a valid email address?
 

andrew.abaye

New member
Local time
Today, 17:24
Joined
Jun 22, 2024
Messages
12
You would be using StaffEmail surely and not "email" which is just a literal and not even a valid email address?
I have tried both same behaviour. It does same thing but nothing happens in my outlook and the staff member don't get any email as well
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:24
Joined
May 7, 2009
Messages
19,268
Thank you. I was simply saying that nothing happens on the Outlook side of thing. It least it should launch outlook if it was not open and the message should be in outbox and when it is sent it will be in sent folder
Outlook was lunch, the mere fact that you received the Security Warning from Outlook on post #3.
you should have Click the "Allow" button on the warning message.
 

andrew.abaye

New member
Local time
Today, 17:24
Joined
Jun 22, 2024
Messages
12
Outlook was lunch, the mere fact that you received the Security Warning from Outlook on post #3.
you should have Click the "Allow" button on the warning message.
I did click on the allow and I expected to see the sent message in the sent folder and in the recipient inbox which did not happen
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:24
Joined
Sep 21, 2011
Messages
14,713
Are you using new outlook at all?
Have you corrected any arguments as per the link I posted?
Google the issue, there are plenty of links, and see if any might apply to you.
You could upload just enough for someone to test for you?
 

Users who are viewing this thread

Top Bottom