Button Coding

  • Thread starter Thread starter ReneeD
  • Start date Start date
R

ReneeD

I have this code set up on my on click event of my button:

Private Sub PERS_USE_OF_COMP_VEH_PROC_Click()
On Error GoTo Err_PERS_USE_OF_COMP_VEH_PROC_Click

Dim stDocName As String

stDocName = "PERS USE OF COMP VEH PROC"
DoCmd.OpenReport stDocName, acNormal
'Print out specified number of report copies
DoCmd.PrintOut , , , , 2

Exit_PERS_USE_OF_COMP_VEH_PROC_Click:
Exit Sub

Err_PERS_USE_OF_COMP_VEH_PROC_Click:
MsgBox Err.Description
Resume Exit_PERS_USE_OF_COMP_VEH_PROC_Click

End Sub

When I click on it, it will print the first copy but when it goes to print
the second copy if gives me an message the the section width is greater than
the page width. If I press ok it will start to print my form and it I press
cancel then I only have the one copy of the report. Any ideas how to resolve
this problem?

Thank you,
Renee
 
Hi Renee,

That is because the acNormal opens the report for printing of one copy
and then closes it. So the PrintOut now applies to the form, not the report.
Try this instead:

Private Sub PERS_USE_OF_COMP_VEH_PROC_Click()
On Error GoTo Err_PERS_USE_OF_COMP_VEH_PROC_Click

Dim stDocName As String

stDocName = "PERS USE OF COMP VEH PROC"
' Open report in preview mode
DoCmd.OpenReport stDocName, acPreview
'Print out specified number of report copies
DoCmd.PrintOut , , , , 2
' Close report
DoCmd.Close acReport, stDocName

Exit_PERS_USE_OF_COMP_VEH_PROC_Click:
Exit Sub

Err_PERS_USE_OF_COMP_VEH_PROC_Click:
MsgBox Err.Description
Resume Exit_PERS_USE_OF_COMP_VEH_PROC_Click

End Sub

Clifford Bass
 
Back
Top