MoveSize not positioning form properly

M

Mark A. Sam

Hello,

In A2007 I am trying to position a form using MoveSize on the Load Event,
but it is not going where I want it to go. For example if I set it as

DoCmd.MoveSize 1000, 1000, getWidth, getHeight

Its position will be
WindowLeft = 495
WindowTop = 135

DoCmd.MoveSize 3000, 3000, getWidth, getHeight

Will yield
WindowLeft = 2490
WindowTop = 1860

This is with the Riboon hid and the Navigation pane closed and AutoCenter =
No Form=Popup
Opening the Ribbon and Navigation pane will yield different results.

Is this a known bug or am I missing something?

Thank you for your help and God Bless,

Mark A. Sam
 
M

Mark A. Sam

If I select Overlapping Windows in Current Database options and set Popup =
No then the form positions correctly. It won't positon where I want it in
Popup or Dialog modes.
 
D

Dirk Goldgar

Mark A. Sam said:
Hello,

In A2007 I am trying to position a form using MoveSize on the Load Event,
but it is not going where I want it to go. For example if I set it as

DoCmd.MoveSize 1000, 1000, getWidth, getHeight

Its position will be
WindowLeft = 495
WindowTop = 135

DoCmd.MoveSize 3000, 3000, getWidth, getHeight

Will yield
WindowLeft = 2490
WindowTop = 1860

This is with the Riboon hid and the Navigation pane closed and AutoCenter
= No Form=Popup
Opening the Ribbon and Navigation pane will yield different results.

Is this a known bug or am I missing something?


I believe the MoveSize method positions a form with respect to its parent
window. For a normal form, this is the inner window of the Access
application. For a popup form, this is the desktop. Consider using Nicole
Calinoiu's FormWindow class for more control over the popup form's position:

http://www.mvps.org/access/forms/frm0042.htm
Forms: Move and Resize form windows from code
 
M

Mark A. Sam

Thanks Dir, bu that didn't work for me. I got compile and runtime errors.
It was helpful to know about the reference points however.
 
D

Dirk Goldgar

Mark A. Sam said:
Thanks Dir, bu that didn't work for me. I got compile and runtime errors.
It was helpful to know about the reference points however.


It has always worked fine for me, so maybe you made some mistakes in using
the class module. Let me know if you want to work on it further.
 
M

Mark A. Sam

Dirk Goldgar said:
It has always worked fine for me, so maybe you made some mistakes in using
the class module. Let me know if you want to work on it further.

I do. I create a "class" module and paste the code from clFormWindows.bas.

When I compiled I got this error:

Compile error: User-defined type, not defined.


pertaining to this declaration:

Public Property Get Parent() As clFormWindow


I pasted the funtion AlignTops into the general module of the popup form,
frmOptions.

Public Sub AlignTops(ByRef frmA As Form, ByRef frmB As Form)
Dim fwA As New clFormWindow, fwB As New clFormWindow
fwA.hwnd = frmA.hwnd
fwB.hwnd = frmB.hwnd
If fwA.Top < fwB.Top Then
fwB.Top = fwA.Top
Else
fwA.Top = fwB.Top
End If

Set fwA = Nothing
Set fwB = Nothing
End Sub

and Called it from the load event

Call AlignTops(ProjectsMAIN, frmOptions)

and got an error:

Compile Error: ByRef argument type mismatch


Thank you Dirk.

God Bless,

Mark
 
D

Dirk Goldgar

Please see my comments inline.

Mark A. Sam said:
I do. I create a "class" module and paste the code from
clFormWindows.bas.

When I compiled I got this error:

Compile error: User-defined type, not defined.


pertaining to this declaration:

Public Property Get Parent() As clFormWindow

Did you save the class module you created with the name "clFormWindow"?
That's the name you should give the class module.
I pasted the funtion AlignTops into the general module of the popup form,
frmOptions.

Public Sub AlignTops(ByRef frmA As Form, ByRef frmB As Form)
Dim fwA As New clFormWindow, fwB As New clFormWindow
fwA.hwnd = frmA.hwnd
fwB.hwnd = frmB.hwnd
If fwA.Top < fwB.Top Then
fwB.Top = fwA.Top
Else
fwA.Top = fwB.Top
End If

Set fwA = Nothing
Set fwB = Nothing
End Sub

and Called it from the load event

Call AlignTops(ProjectsMAIN, frmOptions)

and got an error:

Compile Error: ByRef argument type mismatch

You need to pass actual form references. Try:

Call AlignTops(Forms!ProjectsMAIN, Me)
 
M

Mark A. Sam

Dirk,

Your suggestions did the trick, however I don't think I'll be able to
accomplish my purpose. I'll tell you what I want to do and maybe you will
have a suggestion on how to do it.

I want to save the last size and position of a popup form over a main form.
In the resize event, I save the WindowWidth and WindowHeight to a table. In
the unload event I saved the WindowTop and WindowLeft positions. In the
form Load event I retreive the values and apply them to the MoveSize method.
If I could save the position of the popup relative to the corner of the
desktop, that should do it. The main form will stay maximized.

Thank you and God Bless,

Mark
 
M

Mark A. Sam

Thinking about it, maybe I'll just park the form to one side or the top and
let the user move it wherever it is handy.
 
Top