[AccessD] Question Regarding Changing Multiple Controls (Buttons) on a Form

William Benson (VBACreations.Com) vbacreations at gmail.com
Tue Jan 24 17:58:07 CST 2012


Brad assigning each control of interest to an array element may make future
work easier.
'Module Level
Dim Btn as Contol

Form_Open
For i = 1 to 5
   Set Btn(i) = Forms.form1("Button" & i)
Next
End Sub

Then anywhere you want to mess with them you no longer have to be specific
about the names and you can use 
       For i = lbound (Btn) to ubound(Btn)
             Btn(i).ForeColor = Vblah

      Next
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Brad Marks
Sent: Tuesday, January 24, 2012 6:06 PM
To: Access Developers discussion and problem solving
Subject: [AccessD] Question Regarding Changing Multiple Controls (Buttons)
on a Form

I have set up a little test Form with 5 buttons.

The following code will change the color of the text in each of the
buttons to Blue.  This all works nicely. 


Forms.form1.Button1.ForeColor = vbBlue

Forms.form1.Button2.ForeColor = vbBlue

Forms.form1.Button3.ForeColor = vbBlue

Forms.form1.Button4.ForeColor = vbBlue

Forms.form1.Button5.ForeColor = vbBlue



Now, I would like to set up a loop to change all 5 Buttons' ForeColor
with one statement instead of a statement for each button.

Is it possible to somehow have a variable in the statement?  Here is an
example of what I mean.

Forms.form1. & MyVariable & .ForeColor = vbBlue 


Thanks,
Brad



-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list