How do I move multiple fields on a form using code?

B

Brian Scheele

I am trying to write code that would take several controls on a form and move
them 1.75 inches to the right. I have never used collections in my code
before, so I am not sure what I am doing wrong. A, B, C, etc. are names of
controls on my form. My code gives me this run-time error:

Run-time error '2100':
The control or subform control is too large for this location.

The code halts on this line:
element.Left = element.Left + 1.75 * 1440.

It appears element is equal to the value of the control and not the name of
the control. If I put "A" through "M" in quotes, I get a different runtime
error on the "For each" line:

Run-time error '424':
Object Required

At that point, element=nothing.

Here is my code:

Dim element
Dim colElements As Collection
colElements.Add A
colElements.Add B
colElements.Add C
colElements.Add D
colElements.Add E
colElements.Add F
colElements.Add G
colElements.Add H
colElements.Add I
colElements.Add J
colElements.Add K
colElements.Add L
colElements.Add M
For Each element In colElements
element.Left = element.Left + 1.75 * 1440
Next element



I realize that I could simply avoid using for...each...next routines, but I
am actually running multiple actions on about 100 fields to move controls
around a form based on certain situations.

--


Brian Scheele
IT Manager
Clark Filter
3649 Hempland Road
Lancaster, PA 17601-1323
 
A

Al Campagna

Brian,
Try...
In each control you need to move, set a Tag value of "MoveMe" (no quotes)
Upon some event...

Public Sub MoveRight()
On Error Resume Next
Dim ctl As Control
For Each ctl in Me.Controls
If ctl.Tag = "MoveMe" Then
ctl.left = ctl.Left + (1.75*1440)
End If
Next ctl
End Sub

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
B

Brian Scheele

That worked!

Also, I did not have to do any .add commands since I am only using tagged
controls from me.controls.


--


Brian Scheele
IT Manager
Clark Filter
3649 Hempland Road
Lancaster, PA 17601-1323
 

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