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 » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Printing a report from a form for a single record



 
 
Thread Tools Display Modes
  #1  
Old December 11th, 2009, 04:15 PM posted to microsoft.public.access.forms
forest8
external usenet poster
 
Posts: 196
Default Printing a report from a form for a single record

Hello

At the moment, I have a created a button to print a report but unfortunately
it prints out all the reports and not for a particular record.

How do I set it so that it would only print the report for the current
record selected?

Thank you in advance.
  #2  
Old December 11th, 2009, 04:30 PM posted to microsoft.public.access.forms
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default Printing a report from a form for a single record

Check Access HELP -- look for the complete syntax on the DoCmd.OpenReport
command.

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

"forest8" wrote in message
...
Hello

At the moment, I have a created a button to print a report but
unfortunately
it prints out all the reports and not for a particular record.

How do I set it so that it would only print the report for the current
record selected?

Thank you in advance.



  #3  
Old December 11th, 2009, 04:46 PM posted to microsoft.public.access.forms
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Printing a report from a form for a single record

One other thing: before calling the OpenReport method (with the
WhereCondition argument restricting it to the current record) make sure that
the form's current record is saved with:

Me.Dirty = False

Otherwise any unsaved changes you might have made to the record won't be
reflected in the report.

Ken Sheridan
Stafford, England

forest8 wrote:
Hello

At the moment, I have a created a button to print a report but unfortunately
it prints out all the reports and not for a particular record.

How do I set it so that it would only print the report for the current
record selected?

Thank you in advance.


--
Message posted via http://www.accessmonster.com

  #4  
Old December 11th, 2009, 05:26 PM posted to microsoft.public.access.forms
forest8
external usenet poster
 
Posts: 196
Default Printing a report from a form for a single record

Hi

I'm a bit confused at this point. Do I put this into the code for my print
button or do I put it somewhere else? So far I haven't written any code for
my forms.

Thanks



"KenSheridan via AccessMonster.com" wrote:

One other thing: before calling the OpenReport method (with the
WhereCondition argument restricting it to the current record) make sure that
the form's current record is saved with:

Me.Dirty = False

Otherwise any unsaved changes you might have made to the record won't be
reflected in the report.

Ken Sheridan
Stafford, England

forest8 wrote:
Hello

At the moment, I have a created a button to print a report but unfortunately
it prints out all the reports and not for a particular record.

How do I set it so that it would only print the report for the current
record selected?

Thank you in advance.


--
Message posted via http://www.accessmonster.com

.

  #5  
Old December 11th, 2009, 06:03 PM posted to microsoft.public.access.forms
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Printing a report from a form for a single record

Yes, assuming the button is on a form bound to the table (or to a query) and
you want to open the report for the current record, in the button's Click
event procedure you'd first save the record, and then open the report,
filtering to the record with the same primary key value as the current record
in the WhereCondition argument of the OpenReport method.

I'm guessing you've used the control wizard to set up the button, in which
case the code for its Click event would be something like this:

On Error GoTo Err_cmdOpenReport_Click

Dim stDocName As String

stDocName = "MyReport"
DoCmd.OpenReport stDocName, acPreview

Exit_cmdOpenReport_Click:
Exit Sub

Err_cmdOpenReport_Click:
MsgBox Err.Description
Resume Exit_cmdOpenReport_Click


You'd change it to:

On Error GoTo Err_cmdOpenReport_Click

Dim stDocName As String
Dim stCriteria As String

stDocName = "MyReport"
stCriteria = "[MyID ]= " & Me.[MyID]

' save current record
Me.Dirty = False

' open report in print preview
' filtered to current record
DoCmd.OpenReport stDocName, _
View:=acPreview, _
WhereCondition:=strCriteria

Exit_cmdOpenReport_Click:
Exit Sub

Err_cmdOpenReport_Click:
MsgBox Err.Description
Resume Exit_cmdOpenReport_Click

Where MyReport is the report's name and MyID is the primary key field of the
form's and report's underlying recordsets. This assumes MyID is a number
data type. If its text data type you'd wrap its value in quotes characters
with:

stCriteria = "[MyID ]= """ & Me.[MyID] & """"

Ken Sheridan
Stafford, England

forest8 wrote:
Hi

I'm a bit confused at this point. Do I put this into the code for my print
button or do I put it somewhere else? So far I haven't written any code for
my forms.

Thanks

One other thing: before calling the OpenReport method (with the
WhereCondition argument restricting it to the current record) make sure that

[quoted text clipped - 17 lines]

Thank you in advance.


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200912/1

 




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 04:43 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.