Print Report Macro

  • Thread starter Thread starter rdear
  • Start date Start date
R

rdear

Guest
I am a new user. My macro written to preview the report and print ends up printing all of the records. What should I do to limit the printing to the selected record? I have tried the Printout command ... but I must be doing something wrong. Please help
 
The WHERE clause (I think there is an equivalent line in macro code) must be set to only the 'current' record.

Something along the order of:
"[PrimaryKeyField] = " & [PrimaryKeyReference]

You'll have to figure out how to tell it what record to print. Do you have a popup form, a button off of your active form to print the report, or a parameter question?
 
I have a button on the active form that previews the selected record ... but prints all of the records. Under WHERE command the EXPRESSION BUILDER pops up. Through the expression builder I will find a cmd using "current record?" I will try this and see, but I am grappling in the dark! Thank you for your help.
 
In another dbase, I somehow used the "print current record," but added a print preview ... The button (located on the Form) previewed the report and then you selected "print" from the icon list above.
 
Ok, with a little more data I can help a bit more.

I don't use Macros so bear with me (if you're brave, I'll list the code way to do it at the end).

Your form needs to have a field on it somewhere that shows the Primary Key for that record. It can be invisible and hidden, it just needs to be there. Then when you go to your macro to print the report, the Where clause will be something very similar to this:
WHERE Condition: [PKFieldInTable] = Forms![FormName].[PKFieldOnForm]

The parts in brackets need to be adjusted to match your form/field names. (I hope I did that correctly per Adrianna's example below)

If you code the button directly, the command is simply:
DoCmd.OpenReport "[ReportName]",,,"[PKFieldInTable] = " & Me.[PKFieldOnForm]

Both of these assume that your PK is numeric. If it's text, you'll have to enclose the reference in single quotes.
...= '" & Me.PKField & "'"

Because you're calling it directly from the form you're referencing, the 'Me.' takes the place of explicitly naming the form.
 
Last edited:
David is right.....if you must use a macro or you don't understand the coding....then on your COMMAND BUTTON:
Go to OnClick
Press the ...
Select, create Macro

Select Print
In your arguments section
Select Report for Object Type
Then the specific Report Name
Under WHERE type:
[YourIndexField]= Forms![CurrentFormName]![YourIndexField]

This will tell your Macro to limit the report to select data that matches your current index field....ONE report!!

I would suggest the possibility of creating an Option Group Macro for printing. This will allow you to create one Marco, allow the client to select which reports (from the current form) they would like to print from the tabbed pages....that is assuming that there are several reports associated to the form.

[This message has been edited by Adrianna (edited 06-04-2002).]
 
I believe it WORKED!!! Yayyyy! Thank you for your help! This forum is wonderful!! I have been banging my head against a brick wall for a week!!
 

Users who are viewing this thread

Back
Top Bottom