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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help! I need to output first page only. 1

Status
Not open for further replies.

tamer64

IS-IT--Management
Aug 27, 2007
120
US
Help! I need to export a report in PDF format but the trick is I only need to export the first page only. Here is what I have and it works fine with the exception of the output. It outputs all the pages and I only need the first page. Could page parameters be used somewhere in this string?

On Error GoTo Err_Command66_Click
Dim Response1 As Integer
Dim intCopies As Integer
Dim StrReport1 As String
Dim StrReport2 As String
StrReport1 = "Employee_Summary_1"
StrReport2 = "Employee_Summary_2"

Response1 = MsgBox("Would the print in color ?" _
& vbCr & vbCr & " Press ""Yes"" to print in Color" _
& vbCr & " Press ""No"" to print in Grayscale", _
vbYesNoCancel + vbQuestion, "Print Options")

If Response1 = vbYes Then
intCopies = InputBox("Please enter number of copies", "Copies")
DoCmd.OpenReport StrReport1, acPreview
DoCmd.PrintOut acPages, 1, 1, , intCopies, True
DoCmd.Close acReport, "Employee_Summary_1"
DoCmd.OutputTo acOutputReport, StrReport1, acFormatPDF, "c:\temp\" & StrReport1 & ".pdf"
ElseIf Response1 = vbNo Then
intCopies = InputBox("Please enter number of copies", "Copies")
DoCmd.OpenReport StrReport2, acPreview
DoCmd.PrintOut acPages, 1, 1, , intCopies, True
DoCmd.Close acReport, "Employee_Summary_2"
DoCmd.OutputTo acOutputReport, StrReport2, acFormatPDF, "c:\temp\" & StrReport2 & ".pdf"
Exit_Command66_Click:
Exit Sub

Err_Command66_Click:
MsgBox Err.Description
Resume Exit_Command66_Click
End If
 
I would add a control in a Page section that displays the page. Then try to add some code in the On Page event that would cancel the printing if the Page was greater than 1. I haven't tried this but it would be my first attempt.


Duane
Hook'D on Access
MS Access MVP
 
Duane,

Thank for replying, I am able to print the first page only of the report but It's the export I am having problems with. Once the print is completed, I then have document exported to a temp folder. When using the "Printout" command I can specify what pages to print, I just can't figure what command to use for "DoCmd.OutputTo acOutputReport" to specify the page output.

Any Ideas?
 
Let me try tinkering with that and I will see if I can make that work.
 
I tried adding code to cancel formatting of each section and it seemed to work other than a blank second page

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Cancel = Me.Page > 1
End Sub

Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As Integer)
    Cancel = Me.Page > 1
End Sub
Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
    Cancel = Me.Page > 1
End Sub

Duane
Hook'D on Access
MS Access MVP
 
I have been trying the samething but I get the same error. "An expression you entered is the wrong data type for one of the arguments". It still prints the first page and one blank page but I cannot get the past the error so the output can take place.
 
Duane, I got it to work! I was focusing to much on the report and had overlooked the button which contained an invalid arugment which I was messing around earlier and had forgot to delete it, hence the error message.

Thank you again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top