Solved Loop through all buttons in a form (1 Viewer)

freuzo

Member
Local time
Today, 13:57
Joined
Apr 14, 2020
Messages
98
Hi,
I have a form with many buttons. I need the labels of those buttons to be align on the left so I have this code on the load event :

Code:
btn_1.Alignment = 1
btn_2.Alignment = 1
btn_3.Alignment = 1

and so on...

How can I loop through those buttons to set this one time and for all. I don't want to come back to add a line everytime that I'll have to add a control in that form.

Thanks in advance.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:57
Joined
Oct 29, 2018
Messages
21,467
Something like?
Code:
For x = 1 To 3
    Me.Controls("btn_" & x).Alignment = 1
Next
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:57
Joined
Feb 19, 2002
Messages
43,264
Why are you doing this every time the form opens? Why would you not just fix the layout and be done with it?
 

freuzo

Member
Local time
Today, 13:57
Joined
Apr 14, 2020
Messages
98
Why are you doing this every time the form opens? Why would you not just fix the layout and be done with it?
I'm building in ms access 2013 and there is no way to align button's labels in the design mode (or did I miss someting ? :unsure:).
So I searched and found this code.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:57
Joined
Feb 19, 2002
Messages
43,264
Not sure what your problem is but I do this all the time when I create forms. Please post pictures or the form itself.
 

freuzo

Member
Local time
Today, 13:57
Joined
Apr 14, 2020
Messages
98
Not sure what your problem is but I do this all the time when I create forms. Please post pictures or the form itself.


Capture d’écran 2021-12-06 202357.png


I'm Trying to have all labels align on the left.
If there is a way in the design mode in access 2013 to do that, I didn't see it. So I found the code above (made on the first two buttons as you see).
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:57
Joined
Oct 29, 2018
Messages
21,467
View attachment 96591

I'm Trying to have all labels align on the left.
If there is a way in the design mode in access 2013 to do that, I didn't see it. So I found the code above (made on the first two buttons as you see).
Look for the Alignment property.

1638821334181.png
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:57
Joined
Feb 19, 2013
Messages
16,607
presume you know you can select all the (relevant) controls and all common properties will show so you can set the alignment for all controls in one click
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:57
Joined
Feb 19, 2002
Messages
43,264
Isn't it great when something is easier than you think:)
 

Users who are viewing this thread

Top Bottom