News, links, downloads, tips and tricks on Microsoft Access and related

About Me Search
Name:Alex Dybenko

Location:Moscow, Russia

Wednesday, August 03, 2005

How to Maximize Access Form

In Access this is easy - just run Docmd.Maximize. But once you maximized one form - all others get maximized also. Of course you can run Docmd.Restore, but then forms start to show a lot of visual effects. I think the best approach - is to size form to maximum available size, so it will be looked like it is maximized. Below a sample code, just paste it in a new module, and in Form's Load event add: MaximizeForm Me.hWnd
You can also use same approach for reports, a sample download available at Point Limited site.

Option Compare Database
Option Explicit
'** Constant Definitions:
Private Const GWL_STYLE& = (-16)
Private Const SW_SHOWNORMAL = 1
Private Const SW_SHOWMAXIMIZED = 3
'** Window Style Constants
Private Const WS_DLGFRAME& = &H400000
Private Const WS_THICKFRAME& = &H40000
'** Type Definitions:
Private Type RECT
x1 As Long
Y1 As Long
x2 As Long
Y2 As Long
End Type
'** Function Declarations:
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function IsZoomed Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" _
(ByVal hWnd As Long, ByVal _
nCmdShow As Long) As Long
Private Declare Function MoveWindow Lib "user32" _
(ByVal hWnd As Long, ByVal x As Long, ByVal y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, _
ByVal bRepaint As Long) As Long
Private Declare Function GetParent Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function GetClientRect Lib "user32" _
(ByVal hWnd As Long, lpRect As RECT) As Long
Public Function MaximizeForm(ByVal lngHwnd As Long)
Dim rpt As Access.Report
Dim WinStyle As Long
Dim lngRet As Long

WinStyle = GetWindowLong(lngHwnd, GWL_STYLE)
Call SetWindowLong(lngHwnd, GWL_STYLE, WinStyle)
If IsZoomed(lngHwnd) <> 0 Then
Call ShowWindow(lngHwnd, SW_SHOWNORMAL)
End If
Call GetClientRect(GetParent(lngHwnd), MR)
Call MoveWindow(lngHwnd, 0, 0, MR.x2 - MR.x1, MR.Y2 - MR.Y1, True)
End Function


Anonymous Anonymous said...

This is a pretty clever way to solve the "maximize only the forms I want"- problem!

9:00 PM  
Anonymous Anonymous said...

I decided not to set the form as a pop up, and now all the forms open at 0,0. I am now having problems undoing the change.

12:49 AM  
Blogger Alex Dybenko said...

No sure i understand what you mean...

12:02 PM  
Anonymous Anonymous said...

i really dont get it please help me dude!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

2:45 PM  
Anonymous Anonymous said...

Thanks Alex, much appreciated.

Omar, Australia

8:16 AM  
Anonymous Anonymous said...

After struggling copying & pasting the code, it worked perfectly well. Thank you!

7:18 PM  
Blogger Unknown said...

Thanks ALEX great..... help problem solved.

6:08 AM  
Anonymous Anonymous said...

It really works!!!
Thank you very much!

2:06 PM  
Anonymous Anonymous said...

You Roc Alex! this is awesome. The whole maximize thing has been a pain for ever....спасибо

7:19 PM  
Blogger Kostis said...

Very easy to use and it really works!
Thank you very much!

12:06 PM  

Post a Comment

<< Home