Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-窗体/数据页

如果设置数据表窗体当前行高亮度显示,行色交替

时 间: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源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助