Home All Groups Group Topic Archive Search About

dynamically reposition controls on a form

Author
14 Sep 2006 8:21 PM
Jay
Is there a  way to know the positioning coordinates of a control on a form? 
I need a routine that will for example "move all controls on the form 1 inch
to the right".
The code below would work if I had the value for the variable oldPositionX,
but I cannot figure out how to know this dynamically.
Thanks very much.

Dim ctl As Control, cnt As Integer
For Each ctl In Forms(formName).Controls
      ctl.Move oldPositionX  + 1440
Jay

Author
15 Sep 2006 10:53 PM
Granny Spitz via AccessMonster.com
Jay wrote:
> Is there a  way to know the positioning coordinates of a control on a form? 
> I need a routine that will for example "move all controls on the form 1 inch
> to the right".
> The code below would work if I had the value for the variable oldPositionX,
> but I cannot figure out how to know this dynamically.

You're so close!  You just need to give the control's Left property for its
current horizontal position, and the control's Top property for its vertical
position (in case you need that in the future).  Try it like this:

    Dim ctl As Control
    Const INCH As Long = 1440

    For Each ctl In Forms(formName).Controls
        ctl.Move ctl.Left + INCH
    Next ctl

    Set ctl = Nothing