Asked by:
Uncontrolled printing in Access 2010 when in Windows 10 - can't print specific report

Question
-
I'm using common print techniques - when create a new Purchase Agreement record and want to print same, I call up associated report in Print Preview and do File print - this works fine in Windows 7 but lately in Windows 10, the print job wants to print all records, not the one just created. It looks correct in Print Preview. I've tried putting a Forms criteria in the query used by the report, doing a Refresh on the newly created record and doing a GoTo Last Record before printing, omitting the Form refresh and refreshing individual fields only, but none of that works in Windows 10. All of these adjustments work fine in Windows 7.
And printing an existing record works fine in both Windows 7 and Windows 10.
Are there better ways to make a selected print - would appreciate any tips for resolving this problem
Monday, October 16, 2017 4:46 PM
All replies
-
Can you post your code for us to review in detail.
Daniel Pineault, 2010-2017 Microsoft MVP
Professional Support: http://www.cardaconsultants.com
MS Access Tips and Code Samples: http://www.devhut.netMonday, October 16, 2017 5:55 PM -
The usual approach for this sort of thing is to open the report via a button in the form in which the new record has been inserted. As the report's RecordSource property you can use a query which is restricted by means of a parameter which references a control bound to the primary key of the newly inserted record. Be sure that the records is saved, which you can do with Me.Dirty = False. You can if you wish include two buttons, one to preview the report, the other to print it. The following is code from my InvoicePDF demo which opens the current invoice as a report in print preview:
Private Sub cmdOpenInvoice_Click()
On Error GoTo Err_Handler
Const MESSAGE_TEXT = "No current invoice."
If Not IsNull(Me.InvoiceNumber) Then
' ensure current record is saved
Me.Dirty = False
' open report in print preview
DoCmd.OpenReport "rptInvoice", View:=acViewPreview
Else
MsgBox MESSAGE_TEXT, vbExclamation, "Invalid Operation"
End If
Exit_Here:
Exit Sub
Err_Handler:
MsgBox Err.Description
Resume Exit_Here
End Sub
If the View argument of the OpenReport method is omitted it will be printed.
The report's RecordSource query references the form as follows:
WHERE Invoices.InvoiceNumber=[Forms]![frmInvoice]![InvoiceNumber]
You'll find the demo as InvoicePDF.zip in my public databases folder at:
https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169
Note that if you are using an earlier version of Access you might find that the colour of some form objects such as buttons shows incorrectly and you will need to amend the form design accordingly.
If you have difficulty opening the link copy its text (NB, not the link location) and paste it into your browser's address bar.Ken Sheridan, Stafford, England
- Proposed as answer by Terry Xu - MSFT Tuesday, October 17, 2017 2:48 AM
Monday, October 16, 2017 6:08 PM -
Hi,
this is my response to Ken Sheridan's reply - will be testing same later today. thanks for your reply.
Based on your reply, here’s the code I put in the Event Procedure for the On Click property of the Print button on the form that has a new Purchase Agreement created:
Private Sub Print_Click()
Me.Dirty = False
DoCmd.OpenReport "PurchaseAgreements", View:=acViewPreview
End Sub
The associated query for the report has a criteria parameter against the primary key of the Agreement record.
Your solution works fine on my PC – my client will be running it later this morning at her location – will let you know how it goes – thanks very much for the assistance.
I have a related question – in Access 2010, by default an Embedded Macro is created for the On Click property instead of VBA code in the Event Procedure – would the Save Record and Open Report actions in the macro work the same as the VBA code?
Tuesday, October 17, 2017 12:14 PM -
Based on your reply, here’s the code I put in the Event Procedure for the On Click property of the Print button on the form that has a new Purchase Agreement created:
Private Sub Print_Click()
Me.Dirty = False
DoCmd.OpenReport "PurchaseAgreements", View:=acViewPreview
End Sub
The associated query for the report has a criteria parameter against the primary key of the Agreement record.
Your solution works fine on my PC – my client will be running it later this morning at her location – will let you know how it goes – thanks very much for the assistance.
I have a related question – in Access 2010, by default an Embedded Macro is created for the On Click property instead of VBA code in the Event Procedure – would the Save Record and Open Report actions in the macro work the same as the VBA code?
Tuesday, October 17, 2017 12:14 PM -
Hi again,
Sorry about the duplicate reply - was trying to do bot people that responded.
OK, my client tried the latest and it still wanted to print all records, not the new one just created. Is it possible that we need to do a OpenReport, Print instead of a OpenReport, PrintPreview then a File Print from the PC? Or would a Set Focus or a GoTo Control to reference the key field in the form make the program point to the new record only? This is a quirky problem in my opinion because this works fine at my other clients - I just haven't been able to isolate the issue.
Tuesday, October 17, 2017 2:21 PM -
Is it possible that we need to do a OpenReport, Print instead of a OpenReport, PrintPreview then a File Print from the PC? Or would a Set Focus or a GoTo Control to reference the key field in the form make the program point to the new record only?
Why your customer should be experiencing different behaviour from that experienced by yourself and others I cannot say at this remove. Can you install my demo on your customer's system and test its behaviour? If it prints all invoices, this would point to problem with their system rather than your file.
Regarding your earlier question about using a macro rather than code, the answer is yes.
Ken Sheridan, Stafford, England
- Proposed as answer by Edward8520Microsoft contingent staff Friday, October 27, 2017 9:44 AM
Tuesday, October 17, 2017 3:44 PM -
Hi Ken,
Thanks for the quick reply. Will try what you suggest. And it may well be something on their end only - we do have a workaround that they are using until I solve this - if they get out of the new record and then re-open it as an existing Agreement, it prints fine using the same logic - print preview, etc.
Tuesday, October 17, 2017 3:57 PM -
Hi PeterCV,
What's the current state of this issue? Has your original issue been resolved? If it has, I would suggest you mark useful reply to close this thread. If not, please feel free to let us know your current issue. Thanks for understanding.
Best Regards,
Terry
MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Monday, October 23, 2017 1:29 AM