AcCmdPrint Prints all records

S

scott

I have a button that prints a report with a filter, but when it prints the
report, it ignores the filter. I had messier code worked (it changed the
record source before printing, but that meant it had to open the form in
design, change the record source, go back to print preview and then print)
which I tried to clean up, but I am now stuck on this.

stLinkCriteria = "[All Data].Projsub= " & Forms![Main Menu]![Field5] & " AND
[All Data].Perpost>= '" & Forms![Main Menu]![Field29] & "' And [All
Data].Perpost<= '" & Forms![Main Menu]![Field81] & "'"

stReport = "By Line Item2"

DoCmd.OpenReport stReport, acViewPreview

Reports![By Line Item2].Filter = stLinkCriteria

DoCmd.RunCommand acCmdPrint
 
K

Klatuu

Remove this line:
Reports![By Line Item2].Filter = stLinkCriteria

Change this line:
DoCmd.OpenReport stReport, acViewPreview
To:
DoCmd.OpenReport stReport, acViewPreview, , strCriteria
 

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