Form's Screen Position

  • Thread starter Thread starter Jim Bunton
  • Start date Start date
J

Jim Bunton

I would like to find a form's position
either
Within the Access window
or
on the screen

[so that I can position other forms relative to it when I open them]

? any offers please
 
I would like to find a form's position
either
Within the Access window
or
on the screen

[so that I can position other forms relative to it when I open them]

? any offers please

Look up the MoveSize method in VBA help.
 
Thanks for the reply fredg - how to move size I know about - the problem is
where to move size to.

e.g. if I want to move form B to the left edge of form A

I need to know the position of form A first - then I can position form B
relative to it.

So I need to find the position of Form A (left and down relative to the
window it's displayed in.

Jim

fredg said:
I would like to find a form's position
either
Within the Access window
or
on the screen

[so that I can position other forms relative to it when I open them]

? any offers please

Look up the MoveSize method in VBA help.
 
Jim Bunton said:
Thanks for the reply fredg - how to move size I know about - the problem is
where to move size to.

e.g. if I want to move form B to the left edge of form A

I need to know the position of form A first - then I can position form B
relative to it.

So I need to find the position of Form A (left and down relative to the
window it's displayed in.

If the relative positions of forms A and B are important, you need to
control them both, not just B. Suppose a user move form A to the bottom of
the screen and you simply positioned below and to the right? You'd lose form
B! Position both of them in your code and you will alleviate any of those
problems.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
It can be done with API calls. This code is from API-Guide 3.7 with a couple
of Debug.Prints added to demonstrate Left and Top.

Private Const SW_MINIMIZE = 6
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type WindowPlacement
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long,
lpPoint As POINTAPI) As Long
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As
Long, lpwndpl As WindowPlacement) As Long
Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As
Long, lpwndpl As WindowPlacement) As Long
Dim Rectan As RECT
Public Sub WindowPlacement(strFormName As String)
'Tip submitted by pyp99 ([email protected])
Dim WinEst As WindowPlacement
Dim rtn As Long
WinEst.Length = Len(WinEst)
'get the current window placement
rtn = GetWindowPlacement(Forms(strFormName).hwnd, WinEst)
Rectan = WinEst.rcNormalPosition
Debug.Print Rectan.Left
Debug.Print Rectan.Top
End Sub

Going back to Arvin's suggestion, you can set the form's Moveable property
to False to keep the user from moving the form. Even with this set at False,
you can still move the form in code using the Move method. It will ignore
the Moveable setting.
 
Thanks for the reply Arvin

While I take your point it's not really a great worry to me I will be able
to handle that once I've solved my initail problem i.e. getting info on
where for A is in the first place!

So - back to basics folks -

How do I find out the info about the position of my form in it's current
window (I guess being able to find the dimensions of the window (Access's
window) would be helpful too.

Non of a form's properties seem to provide this info - or am I just being
incredibly stupid???

Thus
? forms!Tree.name
Tree
? forms!Tree.left
error 2465
? forms!tree.top
error 2465
etc I guess!!

Jim
 
Thanks Wayne - and for going the extra mile re setting moveable to false

Wayne Morgan said:
It can be done with API calls. This code is from API-Guide 3.7 with a couple
of Debug.Prints added to demonstrate Left and Top.

Private Const SW_MINIMIZE = 6
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type WindowPlacement
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long,
lpPoint As POINTAPI) As Long
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As
Long, lpwndpl As WindowPlacement) As Long
Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As
Long, lpwndpl As WindowPlacement) As Long
Dim Rectan As RECT
Public Sub WindowPlacement(strFormName As String)
'Tip submitted by pyp99 ([email protected])
Dim WinEst As WindowPlacement
Dim rtn As Long
WinEst.Length = Len(WinEst)
'get the current window placement
rtn = GetWindowPlacement(Forms(strFormName).hwnd, WinEst)
Rectan = WinEst.rcNormalPosition
Debug.Print Rectan.Left
Debug.Print Rectan.Top
End Sub

Going back to Arvin's suggestion, you can set the form's Moveable property
to False to keep the user from moving the form. Even with this set at False,
you can still move the form in code using the Move method. It will ignore
the Moveable setting.

--
Wayne Morgan
MS Access MVP


Jim Bunton said:
I would like to find a form's position
either
Within the Access window
or
on the screen

[so that I can position other forms relative to it when I open them]

? any offers please
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top