如果设置数据表窗体当前行高亮度显示,行色交替
时 间:2007-11-28 13:40:05
作 者:咱家是猫 ID:85 城市:广州
摘 要:实现数据表形式窗体行高亮度显示与行交替变色.
正 文:
我们先依据一个表(表1)建立一个数据表形式的窗体,这个表里有一个ID字段(字段名称例如:货物ID)
在这个窗体中添加一个文本框,命名为:Rank,控件来源
如果货物ID字段是数值型: =DCount("*","表1","货物ID<=" & [货物ID] & "")
如果货物ID字段是文本型: =DCount("*","表1","货物ID<='" & [货物ID] & "'")
然后在本窗体的模块中写如下代码:
Private Sub Form_Current()
On Error Resume Next
Dim cuid As Long
cuid = Me.CurrentRecord
Dim objfrc As FormatCondition
Dim ctl As Control
For Each ctl In Me.Form.Controls
Set objfrc = ctl.FormatConditions(0).Modify(acExpression, , "[Rank] = " & cuid & "")
Next
End Sub
Private Sub Form_Load()
On Error Resume Next
Dim cuid As Long
cuid = Me.CurrentRecord
Dim objfrc As FormatCondition
Dim ctl As Control
For Each ctl In Me.Form.Controls
ctl.FormatConditions(0).Delete
Set objfrc = ctl.FormatConditions.Add(acExpression, , "[Rank] = " & cuid & "")
ctl.FormatConditions(0).BackColor = 255
Next
End Sub
以上代码即可实现当前行高亮显示
如果你还想实现行颜色交替显示,那么把代码改成如下:
Private Sub Form_Current()
On Error Resume Next
Dim cuid As Long
cuid = Me.CurrentRecord
Dim objfrc As FormatCondition
Dim ctl As Control
For Each ctl In Me.Form.Controls
Set objfrc = ctl.FormatConditions(0).Modify(acExpression, , "[Rank] Mod 2 = 0 And [Rank] <>" & cuid & "")
Set objfrc = ctl.FormatConditions(1).Modify(acExpression, , "[Rank] = " & cuid & "")
Next
End Sub
Private Sub Form_Load()
On Error Resume Next
Dim cuid As Long
cuid = Me.CurrentRecord
Dim objfrc As FormatCondition
Dim ctl As Control
For Each ctl In Me.Form.Controls
ctl.FormatConditions(0).Delete
ctl.FormatConditions(1).Delete
Set objfrc = ctl.FormatConditions.Add(acExpression, , "[Rank] Mod 2 = 0 And [Rank] <>" & cuid & "")
Set objfrc = ctl.FormatConditions.Add(acExpression, , "[Rank] = " & cuid & "")
ctl.FormatConditions(0).BackColor = 16777164
ctl.FormatConditions(1).BackColor = 255
Next
End Sub
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access系统自带的日期选择器不...(11.08)
- 分享一下Access工程中的acw...(11.07)
- Access快速开发平台--让有权...(11.04)
- Access快速开发平台--审批选...(11.01)
- ACCESS两张表先各自排序,然后...(10.31)
- Access对子窗体数据进行批量+...(10.30)
- SqlServer中如何用SQL命...(10.29)
- Access报表中的分组功能用代码...(10.28)
- 用Access计算库存结余的一个方...(10.26)
- 最精简的组合框行来源数据快速输入(...(10.25)