How to code report to automatically zoom to 125%

  • Thread starter Thread starter fhsmith7
  • Start date Start date
F

fhsmith7

I use access 2002.

When opening a report, I want it to automatically zoom to 125%. When
closing to minimize. I have tried serveral things without success.

Any assistance is greatly appreceiated.
 
I use access 2002.

When opening a report, I want it to automatically zoom to 125%. When
closing to minimize. I have tried serveral things without success.

Any assistance is greatly appreceiated.

I paste an old function found on the web (with credits):

Sub PreviewAndZoomReport(ReportName As String, ZoomCoeff As Integer)
'function written by Radu Lascae <[email protected]>,
'use it at will standard disclaimer applies
'
'Instead of using DoCmd.RunCommand acCmdZoom150, or another built-in
'constant, you may use the ZoomControl property of the Report object.
'Use with care! The property is not documented anywhere.
'I have found it in a code snippet from a VB5 book.
'
'ZoomControl is a Variant that accepts virtually everything
'that can be converted to a number, positive, negative, small or large.
'The property behaves nicely if "normal" numbers are passed.
'This function allows an integer from 0 = ZoomToFit to 2500(%).
'If the value is out of range, the function uses ZoomToFit.
'The highest readable zoom I could achieve is about 2900(%) (!!!), this
'depends on the minimum scrollbar increment.
'
'The property is available for any open report that has the focus,
'irrespective if the toolbar is visible or not.

'USE:
'Call PreviewAndZoomReport("MyReportName", 125)

On Error GoTo Error_Handler

If Not (ZoomCoeff >= 0 And ZoomCoeff <= 2500) Then
ZoomCoeff = 0
End If

With DoCmd
.OpenReport ReportName, View:=acViewPreview
.Maximize
End With
Reports(ReportName).ZoomControl = ZoomCoeff

Exit Sub
Error_Handler:
MsgBox err.Description
Resume Next
End Sub
 
I paste an old function found on the web (with credits):

Sub PreviewAndZoomReport(ReportName As String, ZoomCoeff As Integer)
    'function written by Radu Lascae <[email protected]>,
    'use it at will standard disclaimer applies
    '
    'Instead of using DoCmd.RunCommand acCmdZoom150, or another built-in
    'constant, you may use the ZoomControl property of the Report object.
    'Use with care! The property is not documented anywhere.
    'I have found it in a code snippet from a VB5 book.
    '
    'ZoomControl is a Variant that accepts virtually everything
    'that can be converted to a number, positive, negative, small or large.
    'The property behaves nicely if "normal" numbers are passed.
    'This function allows an integer from 0 = ZoomToFit to 2500(%).
    'If the value is out of range, the function uses ZoomToFit.
    'The highest readable zoom I could achieve is about 2900(%) (!!!), this
    'depends on the minimum scrollbar increment.
    '
    'The property is available for any open report that has the focus,
    'irrespective if the toolbar is visible or not.

    'USE:
    'Call PreviewAndZoomReport("MyReportName", 125)

    On Error GoTo Error_Handler

    If Not (ZoomCoeff >= 0 And ZoomCoeff <= 2500) Then
        ZoomCoeff = 0
    End If

    With DoCmd
        .OpenReport ReportName, View:=acViewPreview
        .Maximize
    End With
    Reports(ReportName).ZoomControl = ZoomCoeff

    Exit Sub
Error_Handler:
    MsgBox err.Description
    Resume Next
End Sub


Thanks Silivo

When using above code, I get error message from debugger - "invalid
reference to the property zoom control." How do I resolve this? Any
comments are most welcomed.
 
Sub PreviewAndZoomReport(ReportName As String, ZoomCoeff As Integer)

When using above code, I get error message from debugger - "invalid
reference to the property zoom control." How do I resolve this? Any
comments are most welcomed.

I'm sorry: works fine to me without any error.

I'm using Access 2003 sp3.

bye

Silvio
 
I'm sorry: works fine to me without any error.

I'm using Access 2003 sp3.

bye

Silvio

Hey Silvio;
I was using the report "on open" option to place code. Went to command
button and put the code in. It worked. However, I have two reports -
ie. main and catagory. The code opens both together. How to I allow
for just one report to open at a time? See code:

Function aadPreviewReport(frm As Form)
On Error GoTo Err_SmartFormError

Dim strReportName As String, strSQL As String
strSQL = "[" & stFormDataSource & "].[" & stFilterField & "] =
Forms.[" & frm.Name & "].cmbFilterValue"

If IsNull(frm.cmbReports.Value) Or frm.cmbReports.Value = "" Then
Beep
Exit Function
Else
strReportName = frm.cmbReports
End If

If frm.tglFilter = True Then
DoCmd.OpenReport strReportName, acViewPreview, , strSQL

End If

Dim ZoomCoeff As Integer

If Not (ZoomCoeff >= 0 And ZoomCoeff <= 2500) Then
ZoomCoeff = 0
End If

With DoCmd

.OpenReport "catagory", View:=acViewPreview

End With

Reports("catagory").ZoomControl = 125


If Not (ZoomCoeff >= 0 And ZoomCoeff <= 2500) Then
ZoomCoeff = 0
End If

If Not (ZoomCoeff >= 0 And ZoomCoeff <= 2500) Then
ZoomCoeff = 0
End If

With DoCmd

.OpenReport "main", View:=acViewPreview

End With

Reports("main").ZoomControl = 125

End

Exit_SmartFormError:
Exit Function

Err_SmartFormError:
If Err = conErrCommandNotAvailable Or Err =
conErrUserCancelledOperation Then
Resume Next
Else
Call ErrorHandler(Err)
End If

Resume Exit_SmartFormError

End Function


Once again, thanks for you assistance.
 
Back
Top