Email single record on a report

W

weircolin

Hi

I have a form and I am wanting to be able to email the current record
that is showing, but it's not wanting to play. This is the code I am
using.

Dim stDocName As String

stDocName = "rptnewsletterdatabase"
strWhere = "[Reference Number] = " & Me.[Reference Number]
DoCmd.SendObject acReport, stDocName, , strWhere


Can anyone help me?

Thanks

Colin
 
R

Rick Brandt

Hi

I have a form and I am wanting to be able to email the current record
that is showing, but it's not wanting to play. This is the code I am
using.

Dim stDocName As String

stDocName = "rptnewsletterdatabase"
strWhere = "[Reference Number] = " & Me.[Reference Number]
DoCmd.SendObject acReport, stDocName, , strWhere

SendObject doesn't have a WHERE argument like OpenReport does. You have a few
alternatives.

You can exploit a behavior in Access wherein executing a report that is already
opened in preview mode will always produce the same filtering as the one being
previewed. So if you use OpenReport to preview the report with your WHERE
clause and then immediately follow that line of code with your SendObject line
then the report in your Email will be filtered identically.

You can put your WHERE clause in a variable or form control and then have the
Open event of the report run code that evaluates it and applies that same filter
to itself.

You can modify the SQL of the Report's RecordSource query on-the-fly with your
code and then use SendObject.
 
W

weircolin

Hi

Thanks, working great now! Really appreciate it!

Take care

Colin
Rick said:
Hi

I have a form and I am wanting to be able to email the current record
that is showing, but it's not wanting to play. This is the code I am
using.

Dim stDocName As String

stDocName = "rptnewsletterdatabase"
strWhere = "[Reference Number] = " & Me.[Reference Number]
DoCmd.SendObject acReport, stDocName, , strWhere

SendObject doesn't have a WHERE argument like OpenReport does. You have a few
alternatives.

You can exploit a behavior in Access wherein executing a report that is already
opened in preview mode will always produce the same filtering as the one being
previewed. So if you use OpenReport to preview the report with your WHERE
clause and then immediately follow that line of code with your SendObject line
then the report in your Email will be filtered identically.

You can put your WHERE clause in a variable or form control and then have the
Open event of the report run code that evaluates it and applies that same filter
to itself.

You can modify the SQL of the Report's RecordSource query on-the-fly with your
code and then use SendObject.
 

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