CMD Button to export snapshot of report for current record only?

G

Guest

I have one form used to enter data and perform all user actions in the
database.

I found some information on this site on how to create a command button to
generate a print preview of a report for the current visible record only.

I would like to add a command button that would use the same report to
export a snapshot of only the current record. I have not been able to define
a Macro to do this and I haven't found anything on the forum I could use.

My Form is called "Issues"
My report is called "rpt_SingleIssue"

The report will successfully return results for all records in the database.
Thanks in advance for the help.
 
A

Allen Browne

If you preview the report and then export it, you may find it reports the
single record (though I don't like trusting that approach.)

A better idea might be to declare a public string variable, and set it with
the filter string you need to print just one record. Then in the report's
Open event procedure, check the public string, apply it as the report's
filter, and clear the string again.

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

2. In the command button that fires the report, assign the filter value to
the string, e.g.:
gstrReportFilter = "MyIdField = " & Me.[MyIdField]

3. In the Open event procedure of the report, apply the filter:
Private Sub Report_Open(Cancel As Integer)
If gstrReportFilter <> vbNullString Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = vbNullString
End If
End Sub

Use this solution to work around the fact that there is no WhereCondition
argument for SendObject, OutputTo, etc.
 
G

Guest

I'm very new to Access. I tried to muddle my way through this solution to no
avail. I think I created the module correctly. I coudn't figure out all the
right places for the filter and the open event procedure.

Allen Browne said:
If you preview the report and then export it, you may find it reports the
single record (though I don't like trusting that approach.)

A better idea might be to declare a public string variable, and set it with
the filter string you need to print just one record. Then in the report's
Open event procedure, check the public string, apply it as the report's
filter, and clear the string again.

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

2. In the command button that fires the report, assign the filter value to
the string, e.g.:
gstrReportFilter = "MyIdField = " & Me.[MyIdField]

3. In the Open event procedure of the report, apply the filter:
Private Sub Report_Open(Cancel As Integer)
If gstrReportFilter <> vbNullString Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = vbNullString
End If
End Sub

Use this solution to work around the fact that there is no WhereCondition
argument for SendObject, OutputTo, etc.

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

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

Rob T said:
I have one form used to enter data and perform all user actions in the
database.

I found some information on this site on how to create a command button to
generate a print preview of a report for the current visible record only.

I would like to add a command button that would use the same report to
export a snapshot of only the current record. I have not been able to
define
a Macro to do this and I haven't found anything on the forum I could use.

My Form is called "Issues"
My report is called "rpt_SingleIssue"

The report will successfully return results for all records in the
database.
Thanks in advance for the help.
 
A

Allen Browne

Step 1
Unless using Access 2007, click no the Modules tab of the Database Window.
Click New. Access opens a new code window.
Just below any line starting "Option", enter the line.
Save the module with a name such as Module1.
Close.


Step 2
Presumably you already have a button on your form to open the report.
Open this form in design view.
Right-click the command button and choose Propertries.
On the Events tab of the Properties box, click beside On Click.
Now click the "..." beside this.
Access opens the code window.
Add the line to this event procedure, just above the line that starts:
DoCmd.OpenReport ...
Save.
Close.

Step 3
Open the report in design view.
Open the Properties box.
Make sure the title bar of the Properties box reads Report, so you are
looking at the properties of the report (not of a text box.)
On the Event tab, click beside On Open.
Set this property to: [Event Procedure]
Now click the "..." beside this.
Access opens the code window.
Add the code between the "Private Sub..." and "End Sub" lines.

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

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

Rob T said:
I'm very new to Access. I tried to muddle my way through this solution to
no
avail. I think I created the module correctly. I coudn't figure out all
the
right places for the filter and the open event procedure.

Allen Browne said:
If you preview the report and then export it, you may find it reports the
single record (though I don't like trusting that approach.)

A better idea might be to declare a public string variable, and set it
with
the filter string you need to print just one record. Then in the report's
Open event procedure, check the public string, apply it as the report's
filter, and clear the string again.

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

2. In the command button that fires the report, assign the filter value
to
the string, e.g.:
gstrReportFilter = "MyIdField = " & Me.[MyIdField]

3. In the Open event procedure of the report, apply the filter:
Private Sub Report_Open(Cancel As Integer)
If gstrReportFilter <> vbNullString Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = vbNullString
End If
End Sub

Use this solution to work around the fact that there is no WhereCondition
argument for SendObject, OutputTo, etc.

Rob T said:
I have one form used to enter data and perform all user actions in the
database.

I found some information on this site on how to create a command button
to
generate a print preview of a report for the current visible record
only.

I would like to add a command button that would use the same report to
export a snapshot of only the current record. I have not been able to
define
a Macro to do this and I haven't found anything on the forum I could
use.

My Form is called "Issues"
My report is called "rpt_SingleIssue"

The report will successfully return results for all records in the
database.
Thanks in advance for the help.
 

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