Email single record from form as snapshot report

K

k.roberts

I am using the following code to try and email a single record from a
form view, but it is outputting all records.

Private Sub Email_Click()

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "f_Account Management Report"
stLinkCriteria = "[Report ID]=" & Me![Report ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.SendObject acSendReport, "r_AC Man report template", "Snapshot
Format"
DoCmd.Close acReport, "r_AC Man report template"
DoCmd.Close acForm, "f_Account Management Report"

End Sub

I also want to know if it's possible to adapt the code for a continuous
form where each record 'row' has the report id and an email button?

Any help gratefully received.

KLR
 
C

Carl Rapson

I am using the following code to try and email a single record from a
form view, but it is outputting all records.

Private Sub Email_Click()

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "f_Account Management Report"
stLinkCriteria = "[Report ID]=" & Me![Report ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.SendObject acSendReport, "r_AC Man report template", "Snapshot
Format"
DoCmd.Close acReport, "r_AC Man report template"
DoCmd.Close acForm, "f_Account Management Report"

End Sub

I also want to know if it's possible to adapt the code for a continuous
form where each record 'row' has the report id and an email button?

Any help gratefully received.

KLR

It looks like the report you're sending is not the same as the form that
you're opening. The record source of the form "f_Account Management Report"
will have no effect on the record source of the report "r_AC Man report
template". SendObject is opening the report with its default record source.

You will need to open the report with DoCmd.OpenReport, passing the same
WhereCondition. Then use SendObject to send the opened report.

HTH,

Carl Rapson
 
K

k.roberts

I've now amended the code to read as below:-

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "r_AC Man report template"
stLinkCriteria = "[Report ID]=" & Me![Report ID]
DoCmd.OpenReport stDocName, , , stLinkCriteria

'DoCmd.SendObject acSendReport, "r_AC Man report template", "Snapshot
Format"
'DoCmd.Close acReport, "r_AC Man report template"

The code seems to work for the first part as a message box says
outputting pages 1 of 2 etc. Although the report itself doesn't open.
But when it hits the second part of code, it starts to export all
records. I commented out the last two lines to confirm that first part
works ok, but the report still doesn't open.

KLR

Carl said:
I am using the following code to try and email a single record from a
form view, but it is outputting all records.

Private Sub Email_Click()

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "f_Account Management Report"
stLinkCriteria = "[Report ID]=" & Me![Report ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.SendObject acSendReport, "r_AC Man report template", "Snapshot
Format"
DoCmd.Close acReport, "r_AC Man report template"
DoCmd.Close acForm, "f_Account Management Report"

End Sub

I also want to know if it's possible to adapt the code for a continuous
form where each record 'row' has the report id and an email button?

Any help gratefully received.

KLR

It looks like the report you're sending is not the same as the form that
you're opening. The record source of the form "f_Account Management Report"
will have no effect on the record source of the report "r_AC Man report
template". SendObject is opening the report with its default record source.

You will need to open the report with DoCmd.OpenReport, passing the same
WhereCondition. Then use SendObject to send the opened report.

HTH,

Carl Rapson
 
K

k.roberts

I can't believe I have been so dumb! I didn't specify the link
criteria or set view mode to preview - the code now works fine.
KLR

I've now amended the code to read as below:-

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "r_AC Man report template"
stLinkCriteria = "[Report ID]=" & Me![Report ID]
DoCmd.OpenReport stDocName, , , stLinkCriteria

'DoCmd.SendObject acSendReport, "r_AC Man report template", "Snapshot
Format"
'DoCmd.Close acReport, "r_AC Man report template"

The code seems to work for the first part as a message box says
outputting pages 1 of 2 etc. Although the report itself doesn't open.
But when it hits the second part of code, it starts to export all
records. I commented out the last two lines to confirm that first part
works ok, but the report still doesn't open.

KLR

Carl said:
I am using the following code to try and email a single record from a
form view, but it is outputting all records.

Private Sub Email_Click()

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "f_Account Management Report"
stLinkCriteria = "[Report ID]=" & Me![Report ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.SendObject acSendReport, "r_AC Man report template", "Snapshot
Format"
DoCmd.Close acReport, "r_AC Man report template"
DoCmd.Close acForm, "f_Account Management Report"

End Sub

I also want to know if it's possible to adapt the code for a continuous
form where each record 'row' has the report id and an email button?

Any help gratefully received.

KLR

It looks like the report you're sending is not the same as the form that
you're opening. The record source of the form "f_Account Management Report"
will have no effect on the record source of the report "r_AC Man report
template". SendObject is opening the report with its default record source.

You will need to open the report with DoCmd.OpenReport, passing the same
WhereCondition. Then use SendObject to send the opened report.

HTH,

Carl Rapson
 

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