By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

Access Report print filtering

P: 18
Hi, I have a slighly annoying problem, I am using the below code to print out several reports that are linked by InspectionID field, my problem is that this works ... to a point, if I do preview it selects the correct records each time if i then print from preview it prints the single record, but when I use this code, it prints ALL the records, I look at the print queue and its saying pages up to the amount of records where there is data, where no data is on the record it just says 1 , how do i restrict the printout to the nominated record for all of them?

Sub PrintReport()
DoCmd.RunCommand acCmdSaveRecord
On Error GoTo Err_cmdPrintRep_Click
Dim stDocName As Variant
Dim i As Variant
Dim stLinkCriteria As String
Dim tmpPrinter As Printer
Dim filename As String
Set tmpPrinter = Application.Printer 'Default Printer
Set Application.Printer = Application.Printers(2) '("Canon PIXMA iP1000")


stDocName = Array("Page1", "Page2", "Page3", "Page4", "Page5", "Page6", "Page7", "Page8", _
"Page8a", "Page9", "Page9a", "Page10", "Page11", "Page12", "Page13", "Page14", _
"Page15", "Page15a", "Page16", "Page17", "Page18", "Page18a", "Page19", _
"Page19a", "Page20", "Page20a", "Page21", "Page21a", "Page22", "Page23", "Page24", _
"Page25", "Page26", "Page27", "Page27a", "Page27b", "Page28", "Page29", "Page30")

For Each i In stDocName
stLinkCriteria = "[InspectionID] =" & Forms![Booking Form]![InspectionID]
DoCmd.OpenReport i, acViewNormal, , stLinkCriteria 'acNormal Use normal for direct print to printer, acPreview, to preview only
Next i


Exit_cmdPrintRep_Click:
Exit Sub

Err_cmdPrintRep_Click:
MsgBox ("Report Does not Exist") 'Err.Description
Resume Exit_cmdPrintRep_Click

End Sub

thanks
Oldroboman
May 31 '07 #1
Share this Question
Share on Google+
4 Replies


P: 18
Hi again, It would appear that I am looking in the wrong place here, on a lot closer inspection of the reports, i have stopped all the multi pages on most of them, (caused by size of the report page durrrr), but i still have one page that insists on producing 4 pages, but they are all of the same data, so how do I get round that one. the code sent before is obviously working fine. it just seems odd that one out of the 30 should be doing this, maybe Ill try a rebuild to see if that does it.. Ill let you know, but if there is a bright idea there, please let me have it thanks......
May 31 '07 #2

P: 18
Hi again, It would appear that I am looking in the wrong place here, on a lot closer inspection of the reports, i have stopped all the multi pages on most of them, (caused by size of the report page durrrr), but i still have one page that insists on producing 4 pages, but they are all of the same data, so how do I get round that one. the code sent before is obviously working fine. it just seems odd that one out of the 30 should be doing this, maybe Ill try a rebuild to see if that does it.. Ill let you know, but if there is a bright idea there, please let me have it thanks......
Once more it has sorted itself in some respect, It turned out that the report that was causing the aggro was produced from a query, the rest were from tables, I split the report (it was two tables in a query) down to table level and its resloved the issue. they all come out as expected, thanks for the attention, I hope it solves someone elses problem!
May 31 '07 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
Just one thing, although I don't think it will change anything. I would remove setting stLinkCriteria outside the loop. There is no need to reset it each time.

Expand|Select|Wrap|Line Numbers
  1.  
  2. stLinkCriteria = "[InspectionID] =" & Forms![Booking Form]![InspectionID]
  3.  
  4. For Each i In stDocName
  5.     DoCmd.OpenReport i, acViewNormal, , stLinkCriteria 'acNormal Use normal for direct print to printer, acPreview, to preview only
  6. Next i
  7.  
  8.  
Jun 1 '07 #4

MMcCarthy
Expert Mod 10K+
P: 14,534
Once more it has sorted itself in some respect, It turned out that the report that was causing the aggro was produced from a query, the rest were from tables, I split the report (it was two tables in a query) down to table level and its resloved the issue. they all come out as expected, thanks for the attention, I hope it solves someone elses problem!
The query was probably causing a problem because it already had criteria set and this can cause problems when you are trying to pass further criteria through the open report
Jun 1 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.