Ghost Surfer said:
Does anyone know how to center a report (e.g. Sales Figures FOr 2004)
in the MS Access window. The behavior I am looking for is similar to
the "Auto-Center" functionality embedded in the form.
Thanks.
I haven't tested this thoroughly, and it wasn't really designed for this
purpose, but if you download and import Nicole Clainoiu's "clFormWindow"
class from the Access Web:
http://www.mvps.org/access/forms/frm0042.htm
.... then code like this may work to center the report preview window,
more or less:
'----- start of code -----
Sub OpenAndCenterReport(ReportName As String)
Dim fwReport As New clFormWindow
Dim fwAccess As New clFormWindow
Const conFudgefactor = 50
fwAccess.hWnd = hWndAccessApp
DoCmd.OpenReport ReportName, acViewPreview
fwReport.hWnd = Reports(ReportName).hWnd
fwReport.Left = (fwAccess.Width - fwReport.Width) / 2
fwReport.Top = ((fwAccess.Height - fwReport.Height) / 2) -
conFudgefactor
Set fwReport = Nothing
Set fwAccess = Nothing
End Sub
'----- end of code -----
It seems to work on my system, but be aware that the constant
conFudgeFactor was arrived at by trial and error, and I'm not sure
whether it might not vary depending on your screen resolution. I'm sure
there's a more precise way to do this; this was just a quickie attempt.