程序员的知识教程库

网站首页 > 教程分享 正文

实现某字段数据重复后显示颜色(有重复值的字段不能建立索引)

henian88 2024-08-16 17:26:02 教程分享 5 ℃ 0 评论

一、问题描述:

如何在access2003窗体中某一字段重复后,自动显示颜色?如下图:



二、解决方法:

方法一:用菜单上的条件格式工具,如下图:


方法二:在窗体加载事件再加如下代码:

Private Sub Form_Load()
'sfrChild是子窗体控件的名称,me.sfrChild.Form即代表子窗体
SetMyFormat Me.sfrChild.Form, "编号之计数>1"
End Sub

Function SetMyFormat(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
SetMyFormat = True
Set ctl = Nothing
Set fcd = Nothing
End Function


三、效果图:


四、示例下载:http://www.accessoft.com/article-show.asp?id=11066 里下载示例。

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表