根据条件显示不同颜色

主要设计了一个函数,用于按条件进行设置。

Function 设置条件格式(frm As Form, tj As String) As Boolean
Dim ctl As Control
Dim fcd As FormatCondition
For Each ctl In frm.Controls
If ctl.ControlType = acTextBox or ctl.ControlType = acComboBox Then
intCount = 0

ctl.FormatConditions.Delete

ctl.FormatConditions.Add acExpression, acEqual, tj
Set fcd = ctl.FormatConditions.Item(intCount)
With fcd
.BackColor = 255 ‘背景色红色

.ForeColor = 0 ‘前景色黑色
End With
End If
Next ctl
设置条件格式 = True
Set ctl = Nothing
Set fcd = Nothing
End Function

窗体加载事件中的调用代码

Private Sub Form_Load()
设置条件格式 Me.窗体2.Form, “销售员=’33′”
End Sub

组合框中更新后的调用代码

Private Sub Comb1_AfterUpdate()
If Len(Comb1) > 0 Then
设置条件格式 Me.窗体2.Form, “销售员='” & Comb1 & “‘”
End If
End Sub

该函数使用两个参数,第一个代表窗体控件,第二个是条件。

其中窗体2是窗体1的子窗体。

具体请参考示例。

演示图:

示例下载:

数据表窗体根据条件显示不同颜色【Access软件 】

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年3月17日
下一篇 2022年3月17日

相关推荐