Email filtered report

M

Marnie

I need to add a button to a form that emails a report
filtered for only the current record. SendObject does not
allow you to specify a filter for an object.
 
A

Allen Browne

Since SendObject lacks a WhereCondition, you need to apply a filter in the
Open event of the report. To pass the filter string, create a public string
variable, and use the primary key value of the record in the form so that
only that one record is sent.

1. In a standard module (created from the Modules tab of the Database
window), in the General Declarations section (at the top with the Option
statements), enter:
Public gstrReportFilter As String

2. In the Open event procedure of your report:
Private Sub Report_Open(Cancel As Integer)
If Len(gstrReportFilter) > 0 Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = vbNullString
End If
End Sub

3. Place a command button on your form for "email this record", and put
something like this in its Click event procedure:
Private Sub cmdEmail_Click()
If Me.Dirty Then 'Save first
Me.Dirty = False
End If
If Me.NewRecord Then
Beep
Else
gstrReportFilter = "[ID] = " & Me.ID
DoCmd.SendObject acSendReport, "MyReport", ...
End If
End Sub
 

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