Email report page to recipient

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.

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
 
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


Allen Browne said:
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

--
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.

Paul said:
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.

Thanks
 
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.

Reply to group, rather than allenbrowne at mvps dot org.

Paul said:
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


Allen Browne said:
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

Paul said:
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.

Thanks
 
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

--------------------------------

Allen Browne said:
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.

Paul said:
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


Allen Browne said:
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.

Thanks
 
Yes. We are assuming:
- You have a field named "email_id" in your table.
- This table is in the RecordSource of the report.
- You only want to send the records that have this email address in them to
this recipient.

Make sure all your modules have this line at the top (above all the
procedures):
Option Explicit
Then choose Compile from the Debug menu. That should help catch any
mis-spellings.

In the Report_Open code, add these line just above the End Sub:
Debug.Print Me.Filter
Debug.Print Me.FilterOn

After running the code, open the Immediate Window (Ctrl+G), and see if the
filter makes sense, and the second line says True.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Paul said:
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

--------------------------------

Allen Browne said:
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.

Paul said:
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.
 
"TRUE" only prints on 1 line. Seems as if the filter isn't running. Any
Ideas?

Allen Browne said:
Yes. We are assuming:
- You have a field named "email_id" in your table.
- This table is in the RecordSource of the report.
- You only want to send the records that have this email address in them to
this recipient.

Make sure all your modules have this line at the top (above all the
procedures):
Option Explicit
Then choose Compile from the Debug menu. That should help catch any
mis-spellings.

In the Report_Open code, add these line just above the End Sub:
Debug.Print Me.Filter
Debug.Print Me.FilterOn

After running the code, open the Immediate Window (Ctrl+G), and see if the
filter makes sense, and the second line says True.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Paul said:
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

--------------------------------

Allen Browne said:
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.
 
Okay, you are not setting the public string variable correctly.

That could be because:
- You have declared more than one variable with the same name.
- You have misspelled the variable name.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Paul said:
"TRUE" only prints on 1 line. Seems as if the filter isn't running. Any
Ideas?

Allen Browne said:
Yes. We are assuming:
- You have a field named "email_id" in your table.
- This table is in the RecordSource of the report.
- You only want to send the records that have this email address in them
to
this recipient.

Make sure all your modules have this line at the top (above all the
procedures):
Option Explicit
Then choose Compile from the Debug menu. That should help catch any
mis-spellings.

In the Report_Open code, add these line just above the End Sub:
Debug.Print Me.Filter
Debug.Print Me.FilterOn

After running the code, open the Immediate Window (Ctrl+G), and see if
the
filter makes sense, and the second line says True.


Paul said:
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?
 
What's wrong?

Module1:
Option Compare Database
Public gstrReportFilter As String
Option Explicit

Event Procedure:
Private Sub Report_Open(Cancel As Integer)
If gstrReportFilter <> vbNullString Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = Null
End If
Debug.Print Me.Filter
Debug.Print Me.FilterOn

End Sub

Form1:
Public gstrReportFilter As String
Option Compare Database


Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

Dim strTo As String
strTo = "(e-mail address removed)"
gstrReportFilter = "[EMAILID] = """ & strTo & """"
DoCmd.SendObject acSendReport, "MEMO", , _
strTo, , , "Here's your report", , True

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub



Allen Browne said:
Yes. We are assuming:
- You have a field named "email_id" in your table.
- This table is in the RecordSource of the report.
- You only want to send the records that have this email address in them to
this recipient.

Make sure all your modules have this line at the top (above all the
procedures):
Option Explicit
Then choose Compile from the Debug menu. That should help catch any
mis-spellings.

In the Report_Open code, add these line just above the End Sub:
Debug.Print Me.Filter
Debug.Print Me.FilterOn

After running the code, open the Immediate Window (Ctrl+G), and see if the
filter makes sense, and the second line says True.

--
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.

Paul said:
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

--------------------------------

Allen Browne said:
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.
 
Looks like you delcared two public strings with the same name.

Remove this line from Form1's module:
Public gstrReportFilter As String

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Paul said:
What's wrong?

Module1:
Option Compare Database
Public gstrReportFilter As String
Option Explicit

Event Procedure:
Private Sub Report_Open(Cancel As Integer)
If gstrReportFilter <> vbNullString Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = Null
End If
Debug.Print Me.Filter
Debug.Print Me.FilterOn

End Sub

Form1:
Public gstrReportFilter As String
Option Compare Database


Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

Dim strTo As String
strTo = "(e-mail address removed)"
gstrReportFilter = "[EMAILID] = """ & strTo & """"
DoCmd.SendObject acSendReport, "MEMO", , _
strTo, , , "Here's your report", , True

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub



Allen Browne said:
Yes. We are assuming:
- You have a field named "email_id" in your table.
- This table is in the RecordSource of the report.
- You only want to send the records that have this email address in them
to
this recipient.

Make sure all your modules have this line at the top (above all the
procedures):
Option Explicit
Then choose Compile from the Debug menu. That should help catch any
mis-spellings.

In the Report_Open code, add these line just above the End Sub:
Debug.Print Me.Filter
Debug.Print Me.FilterOn

After running the code, open the Immediate Window (Ctrl+G), and see if
the
filter makes sense, and the second line says True.

Paul said:
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.
 
I am using the following, which seems to work:

Event Procedure:
Private Sub report_open(cancel As Integer)
If Len(gstrReportFilter) > 0 Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = vbNullString
End If
End Sub


Form:

Dim stDocName As String

strTo = "(e-mail address removed)"

stDocName = "MEMO"
DoCmd.OpenReport stDocName, acPreview, "gstrReportFilter", "[EMAILID] =
""" & strTo & """"

DoCmd.SendObject acSendReport, "MEMO", , _
strTo, , , "Here's your report", , True

Now what would the OpenRecordSet and Send Object in a loop look like?

Thanks for all the help.

Paul
 
Hi Paul

See help on OpenRecordset() You can create query that just selects the right
email addresses, and use that to open the recordset. In the loop, MoveNext,
until EOF.

For more general suggestions on handling email in Access, Tony Toews has an
FAQ:
http://www.granite.ab.ca/access/email.htm

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Paul said:
I am using the following, which seems to work:

Event Procedure:
Private Sub report_open(cancel As Integer)
If Len(gstrReportFilter) > 0 Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = vbNullString
End If
End Sub


Form:

Dim stDocName As String

strTo = "(e-mail address removed)"

stDocName = "MEMO"
DoCmd.OpenReport stDocName, acPreview, "gstrReportFilter", "[EMAILID] =
""" & strTo & """"

DoCmd.SendObject acSendReport, "MEMO", , _
strTo, , , "Here's your report", , True

Now what would the OpenRecordSet and Send Object in a loop look like?

Thanks for all the help.

Paul



Allen Browne said:
Looks like you delcared two public strings with the same name.

Remove this line from Form1's module:
Public gstrReportFilter As String
 
Back
Top