I can get the report to the e-mail address however it is not filtered.
I
figure the problems is in the third line. Does the field name refer to
the
table column heading and should anything else be in this line?
Code below.
Thanks
-----------------------------
Private Sub Command0_Click()
Dim strTo As String
strTo = "(e-mail address removed)"
gstrReportFilter = "[email_id] = """ & strTo & """"
DoCmd.SendObject acSendReport, "memo", , _
strTo, , , "Here's your report", , True
End Sub
--------------------------------
:
The SendObject does not go in Report_Open.
It goes in the Click event of the command button that you use to fire
off
the report.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
Any Ideas?
When I try this, I get:
Run-time error '2585'
This action can't be carried out while processing a form or report
event.
Code is below:
Private Sub Report_Open(Cancel As Integer)
If gstrReportFilter <> vbNullString Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = Null
End If
Dim strTo As String
strTo = "(e-mail address removed)"
gstrReportFilter = "[email_id] = """ & strTo & """"
DoCmd.SendObject acSendReport, "MEMO", , _
strTo, , , "Here's your report", , True
End Sub
Thanks
:
As you found, the SendObject method does not have a WhereCondition
like
OpenReport does. You can work around that by creating a public
string
variable, setting it to the WhereCondition you want, and then
applying
it
as
the Filter of the report in its Open event.
1. Click the Modules tab of the Database window.
Click New. Access opens a new code window.
In the General Declarations section (top, with the Option
statements):
Public gstrReportFilter As String
Save with a name such as Module1. Close.
2. Open your report in design view.
Open the Properties box (View menu.)
Set the On Open property of the report to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.
Paste in the code below so it looks like this:
Private Sub Report_Open(Cancel As Integer)
If gstrReportFilter <> vbNullString Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = Null
End If
End Sub
3. To send the email to (e-mail address removed) use this code:
Dim strTo as String
strTo = "(e-mail address removed)"
gstrReportFilter = "[YourEmailFieldNameHere] = """ & strTo &
""""
DoCmd.SendObject acSendReport, "YourReportNameHere", , _
strTo, , , "Here's your report", , True
If you want to do that in a loop, you will need to OpenRecordset()
to
get
a
list of the email addresses, and SendObject in a loop.
If you have lots of addresses, Tony Toews has an Access email FAQ
at:
http://www.granite.ab.ca/access/email.htm
I have a report that groups records by e-mail address. There is
no
standard
number of records per e-mail address. Is there any way to send
the
person
their page and not any of the other pages then repeat this for
each
e-mail
address?
Any other suggestions/method of achieving the goal would be
greatly
appreciated.