change label backcolor on all forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an .adp application and I would like to add an interface to allow the
user to change the color for all labels on all forms. I am already using the
AllForms object to change the title on each form based on the user selection
and that works fine.
I am not sure how to add the same type of logic for all labels.. My naming
convention for all lables is as follows: they all start with 'lbl'



Any suggestions would be greatly appreciated



Thanks
ToniS
 
I have an .adp application and I would like to add an interface to allow the
user to change the color for all labels on all forms. I am already using the
AllForms object to change the title on each form based on the user selection
and that works fine.
I am not sure how to add the same type of logic for all labels.. My naming
convention for all lables is as follows: they all start with 'lbl'

Any suggestions would be greatly appreciated

Thanks
ToniS

Open each form (you can use the same procedure you are using to change
the name of the form) in Design View. Cycle through the controls. If
the control is a Label control, change it's backcolor. Then save the
form changes and go on to the next form.


Incorporate the below snippet of code into your current code that
cycles through the form collection to change the form name.

frmName is whatever name you have called this form.

DoCmd.OpenForm frmName, acDesign, , , , acHidden

Dim ctl as Control
For each ctl in Controls
If TypeOf ctl is Label then
ctl.BackColor = vbBlue
End If
Next ctl
DoCmd.Close acForm, frmName, acSaveYes

Continue looping through the forms collection to get the next form.
 
Thanks I think this is exactly what I am looking for, unfortunately I am not
sure what I am doing wrong.... The titles change correctly but the colors do
not, I did test the IntBackColor by setting
Forms(obj.Name).LblTitle.backcolor = intbackcolor and that did work...

What is the purpose of the DoCmd.OpenForm and Close? I did not need that
for changing the title on each form? FYI: The below code is located in
module1 in a public sub....

Below is what I have.

Dim obj As AccessObject
Dim ctl As Controls
Dim dbs As Object

DoCmd.OpenForm Form_Frm_Maintenance_CurrentShow, acDesign, , , , acHidden

For Each obj In dbs.AllForms
Forms(obj.Name).LblTitle.Caption = strTitle

' For Each ctl In Controls
For Each ctl In dbs.AllForms.Controls
If TypeOf ctl Is Label Then
' ctl.BackColor = vbBlue
' ctl.BackColor = intbackcolor
dbs.AllForms.Controls.ctl.BackColor = intBackcolor
End If
Next ctl
Next obj

DoCmd.Close acForm, Form_Frm_Maintenance_CurrentShow, acSaveYes
 
Back
Top