globally changing control properties

  • Thread starter Thread starter Max Yaffe
  • Start date Start date
M

Max Yaffe

Dear Group,

I'd like to globally set & save some control properties so I can make
all my forms look consistent without having to edit each control. For
example, in pseudo-code, I'd like to do something like

for f in all forms
for c in all f.controls
c.background = 14341099
c.FontName = "Arial"
c.FontSize = "7"
end for
end for

and then save the form as edited.

Is there any really slick way to do this?

Thanks,
Max
 
Hi,



Something like:

----------------------
Dim x() As Variant
x = Array(Me.Label0, Me.Label1, Me.Label2, Me.Label4, Me.Text3)
Dim c As Variant

For Each c In x
c.FontSize = 12
Next c
-----------------------


Note that there is late binding involved (relatively slow) and no error
checking is performed as to know if there is a property FontSize for each
element of the array.



Hoping it may help,
Vanderghast, Access MVP
 
Max said:
I'd like to globally set & save some control properties so I can make
all my forms look consistent without having to edit each control. For
example, in pseudo-code, I'd like to do something like

for f in all forms
for c in all f.controls
c.background = 14341099
c.FontName = "Arial"
c.FontSize = "7"
end for
end for

and then save the form as edited.


Dim db As Database
Dim doc As Document
Dim ctl as Control

'some properties don't exist for some types of controls
On Error Resume Next

Set db = CurrentDb()
For Each doc In db.Containers("Forms").Documents
DoCmd.OpenForm doc.Name, acDesign
For Each ctl In Forms(doc.Name).Controls
ctl.BackColor = 14341099
ctl.FontName = "Arial"
ctl.FontSize = 7
Next ctl
DoCmdClose acForm, doc.Name, acSaveYes
Next doc
Set db = Nothing
 
Dear Group,

I'd like to globally set & save some control properties so I can make
all my forms look consistent without having to edit each control. For
example, in pseudo-code, I'd like to do something like

for f in all forms
for c in all f.controls
c.background = 14341099
c.FontName = "Arial"
c.FontSize = "7"
end for
end for

and then save the form as edited.

Is there any really slick way to do this?

Thanks,
Max

Something like this?

Public Sub ChangeProperties()

Dim Db As Database, doc As Document, ctl As Control
Set Db = CurrentDb
On Error GoTo Err_Handler
For Each doc In Db.Containers("Forms").Documents
DoCmd.OpenForm doc.Name, acDesign, , , , acHidden
For Each ctl In Forms(doc.Name)
If TypeOf ctl Is Label Then
ctl.FontName = "Arial"
ctl.FontSize = 7
ElseIf TypeOf ctl is Text Box then
ctl.FontName = "TimesNewRoman"
ctl.FontSize = 10
End If
Next
DoCmd.Close acForm, doc.Name, acSaveYes
Next

Exit_ChangeProperties:
Set Db = Nothing
Exit Sub
Err_Handler:
MsgBox "Error #: " & Err.Number & vbNewLine & Err.Description
Resume Exit_ChangeProperties
End Sub

The above assumes you wish different fonts, etc. for different types
of controls.
Add other control types as needed, or combine them into an If.. Or..
ElseIf .. Then statement.
 
Something like this?

Public Sub ChangeProperties()

Dim Db As Database, doc As Document, ctl As Control
Set Db = CurrentDb
On Error GoTo Err_Handler
For Each doc In Db.Containers("Forms").Documents
DoCmd.OpenForm doc.Name, acDesign, , , , acHidden
For Each ctl In Forms(doc.Name)
If TypeOf ctl Is Label Then
ctl.FontName = "Arial"
ctl.FontSize = 7
ElseIf TypeOf ctl is Text Box then
ctl.FontName = "TimesNewRoman"
ctl.FontSize = 10
End If
Next
DoCmd.Close acForm, doc.Name, acSaveYes
Next

Exit_ChangeProperties:
Set Db = Nothing
Exit Sub
Err_Handler:
MsgBox "Error #: " & Err.Number & vbNewLine & Err.Description
Resume Exit_ChangeProperties
End Sub

The above assumes you wish different fonts, etc. for different types
of controls.
Add other control types as needed, or combine them into an If.. Or..
ElseIf .. Then statement.

Oops...
That should be
If TypeOf ctl Is TextBox
 
Hi,


Indeed, I miss-read the original post; in:

... some control properties...

I understood it as meaning that only "some controls" would have to be
modified, not as "some properties of all controls".



Vanderghast, Access MVP
 
Are you familiar with the autoformat tool? You can save custom formats and
apply them. It has its limitations, but it might do what you need.
 
Friend,

joel-ange sitbon has invited you to join GreenZap and get $50 WebCash to
spend online. Sign up for a FREE GreenZap account and get $50 to spend at
hundreds of the world's premier merchants, many of whom are offering
incredible upfront discounts. Click on the link below to go to GreenZap and
signup! All thanks to joel-ange sitbon.

It's Zappening in the GreenZap Storez.
http://www.greenzap.com/joel1962

If you do not want to receive these emails in the future click the link
below:
http://www.greenzap.com/optout_invite.asp
 
Friend,

joel-ange sitbon has invited you to join GreenZap and get $50 WebCash to
spend online. Sign up for a FREE GreenZap account and get $50 to spend at
hundreds of the world's premier merchants, many of whom are offering
incredible upfront discounts. Click on the link below to go to GreenZap and
signup! All thanks to joel-ange sitbon.

It's Zappening in the GreenZap Storez.
http://www.greenzap.com/joel1962

If you do not want to receive these emails in the future click the link
below:
http://www.greenzap.com/optout_invite.asp
 
Friend,

joel-ange sitbon has invited you to join GreenZap and get $50 WebCash to
spend online. Sign up for a FREE GreenZap account and get $50 to spend at
hundreds of the world's premier merchants, many of whom are offering
incredible upfront discounts. Click on the link below to go to GreenZap and
signup! All thanks to joel-ange sitbon.

It's Zappening in the GreenZap Storez.
http://www.greenzap.com/joel1962

If you do not want to receive these emails in the future click the link
below:
http://www.greenzap.com/optout_invite.asp
 
Friend,

joel-ange sitbon has invited you to join GreenZap and get $50 WebCash to
spend online. Sign up for a FREE GreenZap account and get $50 to spend at
hundreds of the world's premier merchants, many of whom are offering
incredible upfront discounts. Click on the link below to go to GreenZap and
signup! All thanks to joel-ange sitbon.

It's Zappening in the GreenZap Storez.
http://www.greenzap.com/joel1962

If you do not want to receive these emails in the future click the link
below:
http://www.greenzap.com/optout_invite.asp
 
Thanks for all the good ideas.
I think I'm also going try putting a tag on a control so I can specify
formats according to the tag.

Max
 
Back
Top