Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Richland, Washington, USA
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA for ZoomToFit (Access 2000 (9.0.4402 SR-1))

    How do I open a report in Preview mode and have it automatically displayed in full page mode (i.e., "Zoom to Fit" or "Full Page"). Once the form is opened in Preview mode, I can select the Zoom level from the default Print Preview toolbar, but I'd like to do this programmatically within the Report_Open (or other appropriate) event. It seems that I ought to be able to use the 'DoCmd.RunCommand acCmdZoomxxx' but (1) I haven't found an argument that works for 'Zoom to Fit' (there is acCmdZoom50, acCmdZoom100, etc. for 50%, 100% zoom, etc. ) and (2) the code (e.g. for acCmdZoom50) causes an error ("Error 2046: The command or action... isn't available now") when placed in the Report_Open or Report_Activate event routines.

    Is there a way to do this?

    Thanks.

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: VBA for ZoomToFit (Access 2000 (9.0.4402 SR-1))

    As noted, there's no acCmdZoomToFit command to use (this applies in AXP as well). You could use SendKeys to do this but will only work if standard View menu with standard commands is present. (You could create custom menubar for report(s) to ensure this works right.) I normally run Zoom command when opening report from a form, specifying 100% zoom. Example of opening report & specifying Zoom percentage, or using SendKeys to Fit to Window:

    Public Sub OpenReportZoom(strRpt As String)

    DoCmd.OpenReport strRpt, acViewPreview
    DoCmd.SelectObject acReport, strRpt

    ' Specify Zoom percentage:
    DoCmd.RunCommand acCmdZoom100

    ' Use SendKeys for Fit to Window:
    SendKeys "%V", True 'View menu
    SendKeys "Z", True 'Zoom
    SendKeys "F", True 'Fit to Window

    End Sub

    As illustrated, recommend use Select Object to select report, then use Zoom command. If using SendKeys need to set optional "Wait" argument to True or will not work.

    HTH

  3. #3
    Lounger
    Join Date
    Nov 2001
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA for ZoomToFit (Access 2000 (9.0.4402 SR-1))

    This is one way around the problem
    Case conCmdOpenReport
    Screen.ActiveForm.Visible = False
    DoCmd.OpenReport rst![Argument], acPreview
    DoCmd.Maximize
    DoCmd.RunCommand acCmdFitToWindow

  4. #4
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Richland, Washington, USA
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA for ZoomToFit (Access 2000 (9.0.4402 SR-1))

    Mark,

    Thanks for the help. The DoCmd.SelectObject was the piece I was missing. It appears that either DoCmd.RunCommand acCmdFitToWindow (see Rich's response to my post) or acCmdPreviewOnePage (which I just found in the list of RunCommand arguments) will do the "Zoom to Fit" trick.

    So, Mr. Gates, why do you call it 'acCmdFitToWindow' and not 'acCmdZoomToFit'? Arrrrgh.

Posting Permissions

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