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

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » VBA for ZoomToFit (Access 2000 (9.0.4402 SR-1))

    Author
    Topic
    #380186

    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.

    Viewing 0 reply threads
    Author
    Replies
    • #635894

      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

      • #635949

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

      • #636020

        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.

    Viewing 0 reply threads
    Reply To: VBA for ZoomToFit (Access 2000 (9.0.4402 SR-1))

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: