Email report based on current record

insanemom

Registered User.
Local time
Today, 03:56
Joined
Sep 12, 2012
Messages
25
I have a form called frmAFEAapproval. I would like for users to be able to email a report, "rptAFE", of the data for only the current record. I normally use the sendobject for this type of action, but I don't know code to send the current record. The primary key in the table is ID.

Can someone help?
 
You Could use some code along the lines of;
Code:
    Dim stDocName As String

    stDocName = "YourReportName"

    DoCmd.[URL="http://www.fmsinc.com/microsoftaccess/email/sendobject.html"]SendObject[/URL] acReport, stDocName, acFormatSNP, "ToSomeone@Someplace.com", , , "Email Subject", "Email Message", True
Now to make this relevant to the current record you would need your Report to be based on a Query that had the following Criteria;
Code:
Forms!YourFormName!YourID

Also note that you can make any of the items in the SendObject method dynamic by picking them up from your referring form as well.
 
Here's a small sample that demonstrates how it might work.
 

Attachments

Thank you John. I'm very ignorant about code and your example was more that I need. I tried elimiating but couldn't get it to work.

I don't want any message text and need pdf format for the report. So... would the code be:

Dim stDocName As String
stDocName = "frmAFE-100k"
DoCmd.SendObject acReport, stDocName, acFormatPDF, "ToSomeone@Someplace.com", , , "Email Subject", "", True
Forms!frmUSAFEEntry!ID
end sub

is an end if needed?
 
Yes, however I have no idea why you have inserted the highlighted line of code;
Code:
Dim stDocName As String
stDocName = "frmAFE-100k"
DoCmd.SendObject acReport, stDocName, acFormatPDF, "ToSomeone@Someplace.com", , , "Email Subject", "", True
Forms!frmUSAFEEntry!ID [COLOR="Green"]'What are you trying to do here[/COLOR]
end sub

If it is to filter the report you can do that using the query that is populating it (the Report)

Also when you post code please enclose it in the code wrapper as this make it easier to read.

attachment.php
 

Attachments

  • Capture.PNG
    Capture.PNG
    15.2 KB · Views: 2,653
Thank you again.

I don't want to filter based on the ID via the query because the report is is generated based on the user's input in a form. Only records in which the "accept" field is null will be shown in the form. The report is based on each individual record and needs to be sent after the "accept" field is populated. The user may accept several records during each session. Currently I'm using the date records are accepted as the filter for the report. This means if a user logs in and accepts records several times each day and sends the reports each session, the receiptients will get duplicate reports every time a new record is accepted.

Does that make any sense whatsoever?

by the way, are you related to Jlo?
 
Given that you are not actually opening the report you are going to need to filter it at query level, which should be doable with a correctly constructed query, using the criteria;
Code:
Forms!frmUSAFEEntry!ID
 
Wow! I had no idea you could do that. It works great! Thank you so, so much!
 

Users who are viewing this thread

Back
Top Bottom