Moving controls

  • Thread starter Thread starter ChoonBoy
  • Start date Start date
C

ChoonBoy

Is there a way for me to move ControlA in a form and have all the other
controls move along with it while maintaining their exact spaces with
ControlA.

Appreciate full codes for the task.

Thanks
 
Go to Format in the form's Design View. Then select all the controls you
wish to move and either move them all at once, or Group them and move them
all at once.
 
Is there a way for ControlA to be moved in MDE mode and have all the other
controls in the Form moved with it while maintaining their spaces between
ControlA. I know that I can use the Top and Left for the task (Me!number.Top
= Forms!frmfit!Numbertop * 50) but to do it for all controls is too much to
do.

I am thinking of a
1) pop-up box
2) enter the Top & Left position for ControlA
3) click ok and ControlA goes to the prescribed location
4) all other controls move with ControlA and maintaining its spaces.

Appreciate full codes for the job. Thanks in advance.
 
MDE's cannot be altered after they are compiled.

Not a problem moving 50 controls if you use code: (untested):

Public Sub MoveEm(frm As Form)
On Error Resume Next
Dim ctl As Control

For Each ctl In frm.Controls

' Right, Down
DoCmd.MoveSize 50, 10

Next ctl
Set ctl = Nothing
Set frm = Nothing

End Sub

Now, that won't save them since it isn't being done in design view.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
 
Thanks, I tried the codes but I am sure I am not doing it correctly, I tried
to call it from a button but the message "Object required" is displayed (your
codes is in a module)

Private Sub Command0_Click()
MoveEm (form1)
End Sub

Thanks
 
Not a problem moving 50 controls if you use code

Well, you *do* have to make sure that you don't move them to
locations exceed the dimensions of the form, unless you redefine the
size of the form before doing so.
 
Your code works very well, thanks very much.

Arvin Meyer said:
I mad a mistake. MoveSize moves the entire form, not controls. I just tried
this code and it tested fine:

Private Sub Detail_DblClick(Cancel As Integer)

On Error Resume Next
Dim ctl As Control

For Each ctl In Me.Controls
ctl.Left = ctl.Left + 250
ctl.Top = ctl.Top + 100

Next ctl
Set ctl = Nothing

End Sub

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
 
Noted and thanks

David W. Fenton said:
Well, you *do* have to make sure that you don't move them to
locations exceed the dimensions of the form, unless you redefine the
size of the form before doing so.
 
David W. Fenton said:
Well, you *do* have to make sure that you don't move them to
locations exceed the dimensions of the form, unless you redefine the
size of the form before doing so.

Not a problem. I anticipated that so I used:

On Error Resume Next

which just swallows any errors. I funny thing I noted while testing though.
The controls only moved to the bottom as far as the form allowed, and then
began collapsing. But they moved to the right, and simply kept pushing the
form wider until it was off the screen.
 
Not a problem. I anticipated that so I used:

On Error Resume Next

which just swallows any errors.

You see, I'm completely opposed to ever using On Error Resume next
to eat a single anticipated error, since you never know if some
*unanticipated* error might also get eaten.

And I would certainly *never* put it at the top of a sub/function,
since I am convinced from experience that On Error Resume Next
properly respects scope. That is, I've seen places where it appears
that such a statement without a corresponding On Error GoTo 0 to
cancel it appears to stay in effect outside the expected scope. This
is one of the reasons I'm so cautious with using it.

If you know a particular error is going to happen and you want to
ignore it, then trap for that error and throw it away.

Anything else is incredibly bad coding practice, in my opinion.

But then, that also reflects my error trapping philosophy, that you
never construct your error handling such that it will ever possibly
hide useful error conditions.
 
But then, that also reflects my error trapping philosophy, that you
never construct your error handling such that it will ever possibly
hide useful error conditions.

In general a useful philosophy.

I always use On Error Resume Next on function that may run in a query. If
something is wrong, in a query, I do not want to know about it a hundred
times (or even 10). The results will tell me if I have a problem.
 
In general a useful philosophy.

I always use On Error Resume Next on function that may run in a
query. If something is wrong, in a query, I do not want to know
about it a hundred times (or even 10). The results will tell me if
I have a problem.

Interesting distinction.

Not really relevant to a subroutine that resizes and moves controls
on a form, though, right?
 
Back
Top