A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Setting Up & Running Reports
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

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



 
 
Thread Tools Display Modes
  #1  
Old August 24th, 2007, 09:56 PM posted to microsoft.public.access.reports
Rob T[_2_]
external usenet poster
 
Posts: 13
Default CMD Button to export snapshot of report for current record only?

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.
  #2  
Old August 25th, 2007, 04:44 AM posted to microsoft.public.access.reports
Allen Browne
external usenet poster
 
Posts: 11,706
Default CMD Button to export snapshot of report for current record only?

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
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Rob T" wrote in message
...
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.


  #3  
Old August 27th, 2007, 05:52 PM posted to microsoft.public.access.reports
Rob T[_2_]
external usenet poster
 
Posts: 13
Default CMD Button to export snapshot of report for current record onl

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" wrote:

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
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Rob T" wrote in message
...
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.



  #4  
Old August 28th, 2007, 11:06 AM posted to microsoft.public.access.reports
Allen Browne
external usenet poster
 
Posts: 11,706
Default CMD Button to export snapshot of report for current record onl

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
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Rob T" wrote in message
...
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" wrote:

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" wrote in message
...
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.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:01 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.