Control Screen Position

D

David

Hello

Is there any way to get the screen position of a control in order to open a
user form close to it?

David
 
J

John Spencer

Dave,

I don't think that will help determine the location of the control that you
want to place a form next to. It will help to place the form once you
determine the location of the control on a form relative to the SCREEN
coordinates.

I have tried to solve this before and was not able to get a satisfactory
solution.

One technique I did use was to include the form to add as an invisible subform
on the main form. Then I could get the coordinates of the target control and
move the subform to the proper position by changing its Left and top
properties and making the subform visible.


John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
 
K

Klatuu

I really like your solution better and it would be more controlable; however,
my post intended the OP use the MoveSize for the form, not the control.
Perhaps I wasn't clear on that.
 
D

Dirk Goldgar

David said:
Hello

Is there any way to get the screen position of a control in order to open
a
user form close to it?


I haven't tested it thoroughly, and not all the methods and properties used
exist in versions of Access before Access 2003 (or maybe 2002), but code
along these lines seems to work:

'----- start of example code -----
Dim ctlTarget As Access.Control
Dim lngBorderHoriz As Long
Dim lngBorderVert As Long

Set ctlTarget = Me.txtMyTextbox ' Open beside this control

DoCmd.OpenForm "FormToOpen"

lngBorderHoriz = (Me.WindowWidth - Me.InsideWidth) / 2
lngBorderVert = (Me.WindowHeight - Me.InsideHeight) / 2

With Forms("FormToOpen")
.Move _
(Me.WindowLeft - .WindowWidth) + lngBorderHoriz +
ctlTarget.Left, _
Me.WindowTop + lngBorderVert + ctlTarget.Top
End With

'----- end of example code -----
 
M

Marshall Barton

David said:
Is there any way to get the screen position of a control in order to open a
user form close to it?


You can get close using:
Me.WindowLeft + Me.Text0.Left
Me.WindowTop + Me.Text0.Top + Me.Text0.Height

But you will have to add some fudge factors (or difure out
the APIs) for the height of the form's title bar height,
border size and record selector width.
 

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

Top