Results 1 to 7 of 7
  1. #1
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Anyone know how to Print a specific page from an Access Report?

    I need to find a routine that will print a specific page of an access report.

    I might give this a try, BUT I was wondering if there is a simple technique

    My logic would be to use the OnPrint Event and then IF the page No is NOT the one required,
    then Cancel the print Event, however it looks like this would need to be
    covered on many sections in a grouped report.

    Ideally I would want to run this from a custom Toolbar button from the Preview screen, so that the
    desired page was printed.

    The only other thought I had, was to send the report to a pdf document (I have some code for this courtesy an earlier posting),
    and then shell that to adobe reader so the user can use that to view and print.

    Or maybe it could just be sent directly to the Snapshot Viewer.

    Anyone got any ideas or solutions this?
    Andrew

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Open the report in print preview. Then use a line like the following:

    DoCmd.PrintOut PrintRange:=acPages, PageFrom:=5, PageTo:=5

  3. #3
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    [quote name='HansV' post='798127' date='15-Oct-2009 15:09']Open the report in print preview. Then use a line like the following:

    DoCmd.PrintOut PrintRange:=acPages, PageFrom:=5, PageTo:=5[/quote]

    Thanks Hans

    I have a small routine now that requests for a page No from a Pop Up and then uses the code below

    Application.Echo False
    DoCmd.OpenReport strReportName, acViewPreview
    DoCmd.PrintOut acPages, lngPage, lngPage
    DoCmd.Close acReport, strReportName, acSaveNo
    Application.Echo True

    'Not sure about the echo bit, got to test that to se if it interferes with the print

    However, do you know of anyway to detect the name of the Report,
    currently in the Preview window.
    better still to find the page on View in the Preview window.


    In an ideal world, the user would run this from a Button on a Custom Report Toolbar in the PrintPreview Panel

    I guess I could get it to write the name of the report into a global variable when it opens and then clear when it closes.
    That would get me the report name available, but would be brilliant to be able determine this info whilst in preview mode.

    The one that is stumping me for any solution, is the Currently Viewed page Number.

    Guess there might be some Windows API function that would be able to retrieve it, but way beyond me.
    Andrew

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    The currently open report is Screen.ActiveReport, so to get its name, you'd use Screen.ActiveReport.Name.

    Unfortunately, Screen.ActiveReport.Page does not always return the currently viewed page. It returns the number of the last page that has been formatted. If you have a text box that refers to the Pages property (the total number of pages), Screen.ActiveReport.Page will be the total number of pages...

    I don't know of a way to get at the currently viewed page in VBA. Anyone else?

  5. #5
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    [quote name='HansV' post='798135' date='15-Oct-2009 15:42']The currently open report is Screen.ActiveReport, so to get its name, you'd use Screen.ActiveReport.Name.

    Unfortunately, Screen.ActiveReport.Page does not always return the currently viewed page. It returns the number of the last page that has been formatted. If you have a text box that refers to the Pages property (the total number of pages), Screen.ActiveReport.Page will be the total number of pages...

    I don't know of a way to get at the currently viewed page in VBA. Anyone else?[/quote]

    Getting There thanks

    Since I only want this facility to run for certain reports, I have got them to post their name into a global variable.
    When they close they clear the name and the requested page no

    If the Button is fired from the Preview screen then I found that the following code works ok
    This is good because the report has parameters and opening it again would cause them to require input for a second time

    Function PrintPage(strReportName As String)

    Dim lngPage As Long
    Dim dblS As Double, dblE As Double

    On Error GoTo NoPagePrintOutError

    dblS = Time
    lngPage = Nz(glb_PageNo, 0)

    If lngPage = 0 Then Exit Function
    If strReportName & "" = "" Then Exit Function

    DoCmd.PrintOut acPages, lngPage, lngPage
    'I put this in to attempt to get it to arrive at the printer when run without single step
    DoEvents


    Exit Function

    NoPagePrintOutError:
    MsgBox "Cannot print Selected page" & vbLf & Err.Description, vbExclamation
    Exit Function

    End Function

    However the issue I now have is this.

    IF I single step through the code it works fine and Prints the requested page
    BUT if I just let it run, it apears to fire up the print sequence, but nothing arrives at the printer.

    Almost as if it is too quick.

    There is NO line to close the report so cannot see why nothing happens.
    Andrew

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    This is hard to troubleshoot.

    You could insert some lines such as

    Debug.Print lngPage

    before and after the DoCmd.PrintOut line, and see what appears in the Immediate window.

  7. #7
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    [quote name='HansV' post='798142' date='15-Oct-2009 16:08']This is hard to troubleshoot.

    You could insert some lines such as

    Debug.Print lngPage

    before and after the DoCmd.PrintOut line, and see what appears in the Immediate window.[/quote]

    The debug showed same information on both sides of the print

    I tried using a timer to run a 10 sec pause after the printout command to see if it was a timing issue,
    but it made no difference either

    Then I looked at the Print Log on the printer.

    It was being sent the Pop Up form that allowed the users to enter the Page Number.
    This was NOT being closed and so printout was using that instead.

    I added the line to close the popUpDialogue box before it called the PrintOut action and all was good with the world.


    Function PrintPage(strReportName As String)

    Dim lngPage As Long
    Dim strScreenName As String


    On Error GoTo NoPagePrintOutError

    lngPage = Nz(glb_PageNo, 0)

    'Close Open Modal Pop Up Form now data has been collected
    DoCmd.Close acForm, "popGetPageNo", acSaveNo
    DoEvents

    If lngPage = 0 Then Exit Function

    If strReportName & "" = "" Then Exit Function

    DoCmd.PrintOut acPages, lngPage, lngPage
    DoEvents


    Exit Function

    NoPagePrintOutError:
    MsgBox "Cannot print Selected page" & vbLf & Err.Description, vbExclamation
    Exit Function

    End Function




    Shame about the PageNumber from the Preview screen though.

    It's OK as long as you don't scroll back, if you do it returns the highest page previewed.

    Ho Hum
    Andrew

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •