SQL Language to Send One Page of a Report

M

M_

Hi.

I'd like to send a report via e-mail to only one person, rather than
everyone on the list.

I'd also like to add a subject line, addressees, and e-mail text at the same
time.

This is the closest I've gotten, but it doesn't work.

Private Sub cmdPreviewReport_Click()
On Error GoTo Err_cmdPreviewReport_Click

Dim stDocName As String

stDocName = "Assignment E-Mail"

stLinkCriteria = "[NewEntryID]=" & Me![NewEntryID]
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

Exit_cmdPreviewReport_Click:
Exit Sub

Err_cmdPreviewReport_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewReport_Click

End Sub


Thanks for the help.
 
D

Dirk Goldgar

M_ said:
Hi.

I'd like to send a report via e-mail to only one person, rather than
everyone on the list.

I'd also like to add a subject line, addressees, and e-mail text at the
same
time.

This is the closest I've gotten, but it doesn't work.

Private Sub cmdPreviewReport_Click()
On Error GoTo Err_cmdPreviewReport_Click

Dim stDocName As String

stDocName = "Assignment E-Mail"

stLinkCriteria = "[NewEntryID]=" & Me![NewEntryID]
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

Exit_cmdPreviewReport_Click:
Exit Sub

Err_cmdPreviewReport_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewReport_Click

End Sub


Thanks for the help.


You can send the report in various formats using the DoCmd.SendObject
method. Of the available formats, the one that looks most like the original
report is the Snapshot format, but it does require that the recipient have
the free, downloadable snapshot reader.

The other tricky part is to get the report to filter itself to just the data
you want, as you do with your WhereCriteria in the OpenReport method.
SendObject doesn't have the WhereCondition argument, so you need to either
filter your report in the code that opens it, or put logic in the report's
Open event that determines whether it needs to be filtered, creates the
appropriate filter string, and the applies the filter. The latter is rather
simpler, but since I don't know your circumstances, I'll give an example of
the former technique:

'------ start of example code ------
Private Sub cmdEmailAssignment_Click()

stDocName = "Assignment E-Mail"

' Open the report filtered and hidden (so the user doesn't see it).
DoCmd.OpenReport stDocName, acPreview, _
WhereCondition:="[NewEntryID]=" & Me![NewEntryID], _
WindowMode:=acHidden

' Send the report.
DoCmd.SendObject acSendReport, stDocName, acFormatSNP, _
To:=" & Me!EmailAddress, _
Subject:="Assignment", _
MessageText:="Please see the attached document for " & _
"your assignment.", _
EditMessage:=False

' Close the report.
DoCmd.Close acReport, stDocName, acSaveNo

End Sub
'------ end of code ------

There is one problem with using SendObject, and most simple methods of
e-mailing from VBA code -- you have to reply to a confirmation prompt that
yes, you want to allow the program to send a message. That's a security
issue that requires some fiddling to get around.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top