Startup size of report preview window

wjburke2

Registered User.
Local time
Yesterday, 18:47
Joined
Jul 28, 2008
Messages
194
I would like to display report preview windows full size with the report zoom set to fit the page. Is there a way to get preview windows to display full screen zoomed to fit on start up?
 
Last edited:
There's some code here, of course if I haven't gone into enough detail I'll post an example though of course I don't have the luxury of sitting in front of a computer all day thus you may have to wait a day or two for it




Sub aTest()
DoCmd.OpenReport "Report1", acViewPreview
Call sRemoveCaption(Reports!Report1)
End Sub

Private Sub MaximizeRestoredReport(R As Report)
'This code was originally written by Terry Kreft
'Full credits and acknowledgements to him.
'
Dim MDIRect As RECT
' If the Report is maximized, restore it.
If IsZoomed(R.hWnd) <> 0 Then
ShowWindow R.hWnd, SW_SHOWNORMAL
End If

' Get the screen coordinates and window size of the
' MDIClient area.
'This is the line which is different
GetClientRect GetParent(R.hWnd), MDIRect

' Move the Report to the upper left corner of the MDIClient
' window (0,0) and size it to the same size as the
' MDIClient window.

MoveWindow R.hWnd, 0, 0, MDIRect.right - MDIRect.left, _
MDIRect.bottom - MDIRect.top, True

End Sub

Sub sRemoveCaption(rpt As Report)

Dim lngRet As Long, lngStyle As Long
Dim tRECT As RECT, lngX As Long
Dim lngCaptionWidth As Long
Dim lngLeft As Long
Dim lngTop As Long
Dim lngWidth As Long
Dim lngHeight As Long

lngRet = apiGetWindowLong(rpt.hWnd, GWL_STYLE)
lngStyle = (lngRet Xor WS_DLGFRAME Xor _
WS_THICKFRAME) And Not WS_CAPTION
'Need the Xor above to keep window from being sizable
lngRet = apiSetWindowLong(rpt.hWnd, GWL_STYLE, lngStyle)
lngX = apiGetWindowRect(rpt.hWnd, tRECT)

'have to resize the form now
'how much was caption's screenspace
lngCaptionWidth = apiGetSystemMetrics(SM_CYCAPTION)

With tRECT
lngLeft = .left
lngTop = .top
lngWidth = .right - .left
lngHeight = .bottom - .top - lngCaptionWidth
ConvertPIXELSToTWIPS lngLeft, lngTop
ConvertPIXELSToTWIPS lngWidth, lngHeight
DoCmd.SelectObject acReport, rpt.Name, False
DoCmd.Restore
DoCmd.MoveSize lngLeft, lngTop, lngWidth, lngHeight
DoCmd.RunCommand acCmdFitToWindow
End With
Dim frm As Form
For Each frm In Forms
frm.Visible = False
frm.Modal = False
Next
'now use Terry's code here
DoCmd.ShowToolbar "Menu Bar", acToolbarNo
DoCmd.ShowToolbar "Database", acToolbarNo
DoCmd.ShowToolbar "Menu Bar", acToolbarNo
DoCmd.ShowToolbar "Web", acToolbarNo
DoCmd.ShowToolbar "Print Preview", acToolbarNo
DoCmd.ShowToolbar "Custom 1", acToolbarYes
DoCmd.SelectObject acTable, , True

DoCmd.RunCommand acCmdAppMaximize

Call MaximizeRestoredReport(rpt)
DoCmd.RunCommand acCmdWindowHide





End Sub
 
I'll see if I can try it out first

Thanks, I am working on the report right now. I will try to test/debug this solution ASAP. I will let you know how it works. It looks like it has the compoenets I need.
Thanks, again
 
I usually call it like thus

Dim stDocName As String

stDocName = "YourReport"
DoCmd.OpenReport stDocName, acPreview
Call sRemoveCaption(Reports("YourReport"))
 

Users who are viewing this thread

Back
Top Bottom