tags:

views:

848

answers:

4

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.

+2  A: 

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.

addendum

Thanks to Philippe Grondier for finding a relevant code sample, the general idea from the code sample is:

  • declare the following Win32 API elements:
    • 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)
  • if your form is maximized (IsZoomed(frm.hWnd) = True), then restore it (ShowWindow frm.hWnd, SW_SHOWNORMAL)
  • get the MDI clients area from your form's hWnd (GetClientRect GetParent(frm.hWnd, rect))
  • use the rect data to change the position and size of your window (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).

ΤΖΩΤΖΙΟΥ
A: 

You can use MoveSize:

DoCmd.MoveSize 100,100

Further information: http://msdn.microsoft.com/en-us/library/aa141514(office.10).aspx

Remou
+1  A: 

ΤΖΩΤΖΙΟΥ 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.

Philippe Grondier
nice find, Philippe!
ΤΖΩΤΖΙΟΥ
cool, that looks useful, just rather involved for the little app i'm writing!
A: 

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.

Patrick Cuff