K
Kristen
I have tried all of the above - I have Access 2007 and this is the code I am
using to make this work. I need to getthis to happen because I need to print
individual records out for each file as they are updated.
Private Sub cmdPrint_Click()
DoCmd.OpenReport "File Report", acNormal
Reports![File Report].Filter = "UCB Ref# = " & Me![UCB Ref#]
Reports![File Report].FilterOn = True
End Sub
I am about to loose my mind!!!!!! PLEASE HELP.
Thanks.
using to make this work. I need to getthis to happen because I need to print
individual records out for each file as they are updated.
Private Sub cmdPrint_Click()
DoCmd.OpenReport "File Report", acNormal
Reports![File Report].Filter = "UCB Ref# = " & Me![UCB Ref#]
Reports![File Report].FilterOn = True
End Sub
I am about to loose my mind!!!!!! PLEASE HELP.
Thanks.
Sprinks said:Hi, Glenda.
Glad you got it to work. Yes, sometimes at the beginning of developing an
application, a macro can provide a simpler solution. And if it's working for
you, that's great. As things get more complicated, macros' limitations
become troubling, and VBA's flexibility is useful.
In the code I gave you, yes, replace "YourPrimaryKey" with the name of your
primary key field. The reference to YourPrimaryKeyControl is the control on
your form that is bound to your primary key field. This *may* have the same
name as your primary key, but could be different--most developers name their
controls with a naming convention. For example, a textbox bound to a field
named ID might be named txtID.
So, if we assume the following names:
Your report name: MyReport
Your primary key: MyID
The name of the form control bound to MyID: txtID
then:
DoCmd.OpenReport "YourReport", acPreview
Reports![YourReport].Filter = "YourPrimaryKey = " & Me![YourPrimaryKeyControl]
Reports![YourReport].FilterOn = True
becomes:
' Open the report in preview mode
DoCmd.OpenReport "MyReport", acPreview
' Set the filter, filtering my primary key by the value in the current form
record
Reports![MyReport].Filter = "MyID = " & Me![txtMyID]
' Turn the filter on to filter the records for the report
Reports![MyReport].FilterOn = True
Hope that helps.
Sprinks
Glenda said:I just found a much easier method (Access 2003). Instead of all of the code,
I used a Macro. I clicked on Macros, chose "PrintOut" in the dropdown in the
Action Menu. Then at the bottom, chose pages from 1 and page to 1. Then
setup a command button as described in this and instead of choosing
CodeBuilder, chose the Macro and it works.
THANKS again for everyone's help,
--
Glenda
Sprinks said:Hi, Jackson.
To simply print the report, rather than open it in Preview mode, change the
Visual Basic instrinsic constant "acPreview" to "acNormal".
Hope that helps.
Sprinks
:
I goofed - I had it working once and can't get it to print and then close
automatically. Can you help?
:
Hi, Filo.
I'll slow down. Access forms and their controls all have "events"
associated with them. When the event occurs, any procedure defined for the
event runs, giving you a great deal of control over how data is entered, what
the user sees, etc. For example, among others, textboxes have OnGotFocus,
BeforeUpdate, AfterUpdate, OnLostFocus events. Command buttons have, among
others, OnClick and OnDblClick events.
I'd assumed that you would be using a command button on your form to print
the report for the current record. The code I included would be placed in
the CommandButton's OnClick Event procedure. If you've never done this
before, open your form, and display the Toolbox (View, Toolbox). First turn
the wizard off (toggle off the Wand & Stars button on the toolbox). Click on
the command button icon, and draw one on your form. If you wish to rename it
from the Access default name given it, do so now before proceeding.
Right click on the button and select Properties, and click on the Event tab.
Click into the OnClick field, then press the ellipsis to the right of the
field, and select CodeBuilder. Access will create the shell of an OnClick
procedure for you. Cut and paste the code I posted between the Sub and End
Sub lines, change all occurences of "YourReport" to the name of your report,
and save it. This code will now be run when the user clicks on the button.
Hope that helps.
Sprinks
:
what??? I didn't understand a word, where I gona put all wat you write?? a
macro i supose???
:
Hi, Filo.
Assign a Filter using the primary key of the current record, and turn the
filter on:
DoCmd.OpenReport "YourReport", acPreview
Reports![YourReport].Filter = "YourPrimaryKey = " & Me![YourPrimaryKeyControl]
Reports![YourReport].FilterOn = True
Hope that helps.
Sprinks
:
Hello, I want to crate a macro that prints just one record of one form linked
to a table with 54 records, when I try to print the report the 54 records are
printed¡¡¡