Reputation:
So I have an Access application, and I'd like some forms to be maximised when they are opened, and others to be medium-sized when they are opened. However, if I try something like this:
Private Sub Form_Activate()
DoCmd.Maximize
End Sub
or
Private Sub Form_Activate()
DoCmd.Restore
End Sub
it has the effect of maximizing or restoring every open window, which isn't what I'm looking for.
Is there any way around this?
I'm using Access 2003.
Upvotes: 1
Views: 15475
Reputation: 95941
Access is an MDI (Multiple Document Interface) application, and this is how they work: either all sub-windows are maximized, or none.
What you need to do, is find a way to discover the dimensions of the Access application window, and then programmatically set the form's .InsideWidth and .InsideHeight properties. The Application
object has a hwndAccessApp
that probably can be used with some Windows API call to find out its width and height.
Thanks to Philippe Grondier for finding a relevant code sample, the general idea from the code sample is:
struct Rect
(Type Rect…
in VBA)const SW_SHOWNORMAL = 1
(for ShowWindow)GetParent
(given a hwnd, get its parent's hwnd)GetClientRect
(retrieve position and size from a hwnd)IsZoomed
(boolean; true if window is maximized)ShowWindow
(change the state of a window)MoveWindow
(to change the position and size of a window)IsZoomed(frm.hWnd) = True
), then restore it (ShowWindow frm.hWnd, SW_SHOWNORMAL
)GetClientRect GetParent(frm.hWnd, rect)
)MoveWindow frm.hWnd, 0, 0, rect.x2-rect.x1, rect.y2-rect.y1
)(The above is basically the explanation of the code sample; I didn't copy-paste the code because I wasn't sure if the author allowed it).
Upvotes: 2
Reputation: 29796
There are a couple of options here: http://www.jamiessoftware.tk/articles/resolution.html
I used ADHResize in the past and it got the job done.
Upvotes: 0
Reputation: 11138
ΤΖΩΤΖΙΟΥ is 100% right when saying that either all are maximised, or none. If you really want to manage this issue, you'll have to read a little bit here (look at the code proposed and the way to call it), understand what is done, and eventually build your own solution depending on your needs.
Upvotes: 2
Reputation: 91356
You can use MoveSize:
DoCmd.MoveSize 100,100
Further information: http://msdn.microsoft.com/en-us/library/aa141514(office.10).aspx
Upvotes: 0