Gustav Brock
Gustav at cactus.dk
Fri Feb 3 04:49:08 CST 2006
Hi Joe If you prefer the report handles this "by itself", we dealt with the topic back in 2002: > OK, never say never, here's how you can achieve this. > > As several have noted, no event of the report is fired after the report > has been formatted and displayed. Thus you'll have to make your own > event. > This can be done with a hidden timer form which is opened by the report, > adjusts the zoom level and closes automatically. > > First create a simple no-nonsense form. > Named it frmReportZoom. > Set its TimerInterval to 1. > > Add this code to the Timer event: > > <code> > > Private Sub Form_Timer() > > Static lngZoomFactor As Long > Static strReportName As String > Static booResized As Boolean > > Dim lngReport As Long > > If lngZoomFactor = 0 Then > strReportName = Nz(Me.OpenArgs, vbNullString) > If Len(strReportName) > 0 Then > ' Extract zoom constant and report name. > lngZoomFactor = Val(strReportName) > strReportName = Mid(strReportName, Len(CStr(lngZoomFactor)) + 1) > End If > If Len(strReportName) = 0 Then > ' Nothing to do. > booResized = True > Else > ' Validate zoom constant. > Select Case lngZoomFactor > Case _ > acCmdZoom10, _ > acCmdZoom25, _ > acCmdZoom50, _ > acCmdZoom75, _ > acCmdZoom100, _ > acCmdZoom150, _ > acCmdZoom200, _ > acCmdFitToWindow > ' Zoom factor/method accepted. > Case Else > ' Zoom constant cannot be used. > ' Nothing to do. > booResized = True > End Select > End If > End If > > If booResized = False Then > On Error Resume Next > lngReport = Reports.Count > If lngReport = 0 Then > ' No reports are open. > ' The report may have been printed without a preview. > booResized = True > ElseIf Reports(lngReport - 1).Name = strReportName Then > ' The report is open. Resize it. > DoCmd.SelectObject acReport, strReportName > DoCmd.RunCommand lngZoomFactor > If Err = 0 Then > ' The report has be "rezoomed". > booResized = True > Else > ' Try to resize the report at next timer event. > End If > End If > On Error GoTo 0 > End If > > If booResized = True Then > ' Report has been resized or is gone. > DoCmd.Close acForm, Me.Name > End If > > End Sub > > </code> > > Armed with this, add this code in your report's Page event: > > <code> > > Private Sub Report_Page() > > ' Specify requested zoom level (percent). > ' Useful values are from 10 to 200 percent. > ' Specify zero if report shall fit to window. > Const clngZoomLevel As Long = 0 > ' Name of timer form which will resize this report. > Const cstrFormName As String = "frmReportZoom" > > Dim lngZoomLevel As Long > Dim strOpenArgs As String > > ' Adjust zoom level at first page view only. > If Me.Page = 1 Then > ' Wrap zoom level into a valid constant. > Select Case clngZoomLevel > Case Is <= 0 > lngZoomLevel = acCmdFitToWindow > Case Is <= 10 > lngZoomLevel = acCmdZoom10 > Case Is <= 25 > lngZoomLevel = acCmdZoom25 > Case Is <= 50 > lngZoomLevel = acCmdZoom50 > Case Is <= 75 > lngZoomLevel = acCmdZoom75 > Case Is <= 100 > lngZoomLevel = acCmdZoom100 > Case Is <= 150 > lngZoomLevel = acCmdZoom150 > Case Is <= 200 > lngZoomLevel = acCmdZoom200 > Case Else > lngZoomLevel = acCmdZoom200 > End Select > ' Concatenate zoom constant and report name to > ' one string variable to be passed to the form. > strOpenArgs = CStr(lngZoomLevel) & Me.Name > ' Open the form hidden. > DoCmd.OpenForm cstrFormName, acNormal, , , , acHidden, strOpenArgs > Else > ' In preview mode, cstrFormName has closed itself now. > ' In print mode, cstrFormName will be closed at page 2. > DoCmd.Close acForm, cstrFormName, acSaveNo > End If > > End Sub > > </code> > > Open the report and it will "rezoom" instantly. /gustav >>> jmhecht at earthlink.net 02-02-2006 21:37:42 >>> I have reports that I have code to maximize on opening. Does anyone know the code to set the preview size automatically to 100% Joe Hecht jmhecht at earthlink.net