Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DoCmd.OpenReport stDocName, acPreview Question, Access 2007 (12.0.6562.5005

    The following code was provided by MarkD & Francois from a Closed Thread 2004-03-10 18:55

    DoCmd.OpenReport stDocName, acPreview Question (a2k (9.0.6926) SP-3 Jet 4.0 SP-7)


    The following is code is in a Form that prints a report and cycles a Report Preview from Last Page to First Page

    This code has worked without problems with Access 2000-2003 for the past 6 years

    DoCmd.OutputTo acOutputReport, stDocName, acFormatTXT, _
    strOutput, False


    OpenReportToLastToFirstPagePreview (stDocName)

    Public Function OpenReportToLastToFirstPagePreview(strRpt As String)

    Dim strPages As String
    Dim intLen As Integer
    Dim n As Integer

    DoCmd.OpenReport strRpt, acViewPreview
    ' Determine number of pages:
    strPages = CStr(Reports(strRpt).Pages)
    ' Specify Zoom percentage:
    DoCmd.RunCommand acCmdFitToWindow
    DoCmd.SelectObject acReport, strRpt
    ' Use SendKeys to select Navigation box Page number:
    SendKeys "{F5}", True
    SendKeys strPages, True
    SendKeys "{ENTER}", True

    'Pause 1 second, then go back to Page 1:
    Sleep 1000
    DoCmd.SelectObject acReport, strRpt
    SendKeys "{F5}", True
    SendKeys "1", True
    SendKeys "{ENTER}", True
    SendKeys "%vzz" ' Alt v = Menu, z=Zoom, z = 100%

    End Function '==================================

    I'm trying to run the code with Access 2007 (12.0.6562.5005) SP2 MSO (12.0.6562.5003) in Access 2000 format and I'm getting the following message:

    Microsoft Office Access
    You canít use the ApplyFilter action on this window.

    You tried to use the ApplyFilter action or method, but you didnít apply the filter to a table, query, form, or report.
    You may have applied the filter to a form, but the form wasnít open in Form or Datasheet view.
    You may have applied the filter to a report but didnít use the ApplyFilter action in a macro specified by the OnOpen property setting.

    Use the SelectObject action or method to select the table, query, form, or report before applying the filter. OK

    Any help would be appreciated

    John

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    The code uses SendKeys {F5} , which is the coding equivalent of pressing the F5 Key.
    If you actually press the F5 key yourself while previewing a report, the same error message appears. so it seems that the role of F5 has changed.
    It appears to me that Alt + F5 is now supposed to set the focus on the page number box.
    To use this you would need to change the code to
    SendKeys "%{F5}"
    But the results were highly variable for me. The existing number was not always selected, so when a new number was entered via the next line of code, it was not correct.

    I see that PageDown and PageUp can be used to move through the pages of a report, (once FitTowindow is selected.)
    You might be able to do something with them instead.
    Regards
    John



  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the help

    When printing a 4 page report I was ending up with 41 in the box number
    When printing a 82 page report I was ending up with 821 in the box number
    When printing a 125 page report I was ending up with 1251 in the box number

    So I added the backapace commands to clear the box before sending the 1

    Is there a better way to accomplish this?

    Thanks, John

    'My final code that seems to work for the time being
    Public Function OpenReportToLastToFirstPagePreview2007(strRpt As String)

    Dim strPages As String
    Dim intLen As Integer
    Dim n As Integer

    DoCmd.OpenReport strRpt, acViewPreview
    ' Determine number of pages:
    strPages = CStr(Reports(strRpt).Pages) ' save last page number
    ' Specify Zoom percentage:
    DoCmd.RunCommand acCmdFitToWindow
    DoCmd.SelectObject acReport, strRpt

    'Use SendKeys to select Navigation box Page number:

    SendKeys "%{F5}", True 'select navigation box page number
    SendKeys strPages, True 'last page number
    SendKeys "{ENTER}", True 'go last page

    'Pause 2 second, then go back to Page 1:
    Sleep 2000
    DoCmd.SelectObject acReport, strRpt

    SendKeys "%{F5}", True 'select navigation box page number
    SendKeys "{BACKSPACE}", True '41 - clears 41 from box number
    SendKeys "{BACKSPACE}", True '821 - clears 821 from box number, if over 9 checks
    SendKeys "{BACKSPACE}", True '1251 - clears 1251 from box number if over 99 checks

    SendKeys "%{F5}", True 'select navigation box page number
    SendKeys "1", True 'set to page 1
    SendKeys "{ENTER}", True 'go to page 1

    SendKeys "%vzz" ' Alt v = Menu, z=Zoom, z = 100%

    End Function

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Using Backsapce sounds like a good solution.
    Presumably if you Backspace when there is nothing there to be cleared, you don't get an errors.
    Regards
    John



Tags for this Thread

Posting Permissions

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