Chai,
This code will copy the format conditions from one control to all the combos
and text boxes on the form. Set the controls tag property to "NOT" if you
don't want to format it. Also, it works with format conditions that include
the control name in the the expression. You can rework the .Add line to
make it do other types of formats besides expressions.
HTH,
Josh
Function FormatForm(frm As Form, CopyCtl As Control)
Dim ctl As Control
Dim fmt As FormatCondition
Dim s As String
For Each ctl In frm.Controls
If ctl.Tag = "NOT" Then GoTo Next_Ctl
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Not ctl.Name = CopyCtl.Name Then
DelFormatExp ctl
For Each fmt In CopyCtl.FormatConditions
With ctl.FormatConditions _
.Add(acExpression, ,
CVar(ReplaceText(CStr(fmt.Expression1), CopyCtl.Name, ctl.Name)))
.BackColor = fmt.BackColor
.FontBold = fmt.FontBold
.ForeColor = fmt.ForeColor
End With
Next fmt
End If
End Select
Next_Ctl:
Next ctl
End Function
Function DelFormatExp(ctl As Control)
Dim fmt As FormatCondition
For Each FormatCondition In ctl.FormatConditions
FormatCondition.Delete
Next FormatCondition
On Error Resume Next
ctl.FormatConditions(0).Delete
End Function
Function AddFormatExp(ctl As Control, stExpression1 As Variant, intBackColor
As Integer, intForecolor As Integer, bolFontBold As Boolean) As Boolean
Dim Condition As FormatCondition
Dim i As Integer
Select Case ctl.ControlType
Case acTextBox, acComboBox
With ctl.FormatConditions _
.Add(acExpression, , stExpression1)
.BackColor = intBackColor
.FontBold = bolFontBold
.ForeColor = intForecolor
End With
Case Else
AddFormat = False
End Select
Exit Function
End Function