我有一个带有单个组合框的测试表单,其中我根据框中选择的选项设置了一些条件格式。组合框的标签为#34;条件。"
要更改条件格式,我有一个名为on form的子打开。将来,这将适用于许多带有"条件"的组合框。标签
Private Sub ApplyCondFormatting()
Dim objFrc As FormatCondition
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "Conditional" Then
With ctl
'Remove format conditions
.FormatConditions.Delete
MsgBox ("Test")
'Apply new format conditions
Set objFrc = .FormatConditions.Add(acExpression, acEqual, "[Value] = Correct")
Set objFrc = .FormatConditions.Add(acFieldValue, acEqual, "[Value] = Incorrect")
'Specify the formating conditions
.FormatConditions(0).BackColor = RGB(0, 255, 0)
.FormatConditions(0).Enabled = True
.FormatConditions(1).BackColor = RGB(255, 0, 0)
.FormatConditions(1).Enabled = True
End With
End If
Next ctl
Set objFrc = Nothing
End Sub
出现MsgBox,因此宏 正常运行,但它不会删除旧格式或添加新格式。我错过了什么?
答案 0 :(得分:1)
这应该有用,但它仅适用于"暂时"到目前开放的表格。
如果您想将其永久化,则必须事先在设计视图中打开表单
DoCmd.OpenForm strMyForm, acDesign
然后保存
DoCmd.Save acForm, strMyForm