Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Way To Stop Access From Printing Subform With Reports?

Status
Not open for further replies.

LittleC

Programmer
Dec 19, 2003
13
US
Hey,

I've gotten helpful advice from the experts @ Tek-Tips in the past & thought i'd ask for assistance on this one.

When i attempt to use an on click event to print reports, the subform also prints. Is there a fix for this bug in Access 97 or is there something wrong with my code?

Here is the code i'm using to open a subform from which the user may select reports to be printed:

Code:
'===========================================

Private Sub Command1_Click()

Dim strDocName As String
Dim strLinkCriteria As String

strDocName = "Customer Subform"
strLinkCriteria = "[ID]=" & "'" & Me![ID] & "'"
DoCmd.OpenForm strDocName, , , strLinkCriteria

End Sub

'=====================================

Here is the code i'm using to print out one of the reports from the subform:

Code:
'=====================================

Private Sub Command2_Click()
    
Dim strDocName As String
Dim strFilter As String

strDocName = "CoverLetter"
strFilter = "ID = Forms!frmIssues!ID and OrderNumber = Forms!frmIssues!OrderNumber"
DoCmd.OpenReport strDocName, acNormal, , strFilter
DoCmd.PrintOut acPrintAll, , , acHigh, 2, 1
       
strDocName = "OrderForm"
strFilter = "ID = Forms!frmIssues!ID and OrderNumber = Forms!frmIssues!OrderNumber"
DoCmd.OpenReport strDocName, acNormal, , strFilter
DoCmd.PrintOut acPrintAll, , , acHigh, 2, 1
DoCmd.Close acDefault, , acSavePrompt
        
End Sub

'==========================================

When a user clicks on the button on the subform, the CoverLetter and OrderForm reports print out OK, but the Customer Subform also prints more than once. However, when the same on click event is used to run the same code from the Customers main form, the Customers form does not print out with the two reports. It's only a problem with the subform, which is something like a dialog box with the popup property set to yes.

I'm pulling what little hair i have left out over this one. Is there anyone who might be able to save me from going bald? ;-)

Thanks in advance!

 
For anyone interested, here is a fix for the problem:

Private Command1_Click()

Me.Refresh
Me.Visible = False

Dim strDocName As String
Dim strFilter As String

strDocName = "CoverLetter"
strFilter = "ID = Forms!frmIssues!ID and OrderNumber = Forms!frmIssues!OrderNumber"
DoCmd.OpenReport strDocName, acPreview, , strFilter
DoCmd.PrintOut acPrintAll, , , acHigh, 2, 1
DoCmd.Close acDefault, , acSavePrompt

strDocName = "OrderForm"
strFilter = "ID = Forms!frmIssues!ID and OrderNumber = Forms!frmIssues!OrderNumber"
DoCmd.OpenReport strDocName, acPreview, , strFilter
DoCmd.PrintOut acPrintAll, , , acHigh, 2, 1
DoCmd.Close acDefault, , acSavePrompt

End Sub

The Me.Visible = false code kept the popup form from being visible so it would not print with the reports. The DoCmd.Close acDefault ,, acSavePrompt closed the print preview after two copies of each report printed.

Thanks to the two who gave me the idea to hide the form before printing!

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top