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!

How Do i Prevent Access From Printing Subform When Reports Print Out? 1

Status
Not open for further replies.

LittleC

Programmer
Dec 19, 2003
13
US
Hello,

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
 
Goto the design view of the form/report and then the properties of the subform. Select the Format tab and set the "Display When" property to "Screen Only" and see if that does what you are after.

I did not see away to do this through code, but that doens't mean you can't.


Dave
 
Thanks for catching that foolio12, I just now saw all the crossposting.

Dave
 
Glohamar:

Thank you! i'll give that a whirl & let you know how it works out.

=====================================

foolio:

I'm feeling like the fool, as i see i've breached a message board etiquette. My thought was that posting in different threads would result in different opinions as to how to solve the problem. My apologies for any inconvenience i've caused anyone.
 
I tried this fix before Glohamar's suggestion & it did the trick:

Code:
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
Code:
 Me.Visible = false
code kept the popup form from being visible so it would not print with the reports. The
Code:
 DoCmd.Close acDefault ,, acSavePrompt
closed the print preview after two copies of each report printed.

Thanks Glohamar for giving me the idea to set the visible property to false. You deserve a star! :)



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top