根据你的短消息要求:
先依据一个表(表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
以上代码即可实现当前行高亮显示
用上面这段程序 运行后窗体在不断的刷新 。
我用access911上找了一段代码
给大家看看
'access911.net 示例系列之
' 在连续窗体中如何反白显示获得焦点的记录
Private Sub Form_Open(Cancel As Integer)
'注意,本示例中 [城市ID] 文本框的数据源是 [城市ID] 字段,
'该字段是自动编号字段,能够唯一标识记录
Dim ctl As Control
For Each ctl In Me.Form
If ctl.ControlType = acTextBox Then
ctl.FormatConditions.Add acExpression, acEqual, 1
ctl.FormatConditions(0).Modify acExpression, , "[城市ID] =-1"
ctl.FormatConditions(0).ForeColor = vbWhite
ctl.FormatConditions(0).FontBold = True
ctl.FormatConditions(0).BackColor = vbBlack
ctl.OnGotFocus = "=b([城市ID])"
End If
Next ctl
End Sub
Function b(ByVal a As Long)
Dim ctl As Control
For Each ctl In Me.Form
If ctl.ControlType = acTextBox Then
ctl.FormatConditions(0).Modify acExpression, , "[城市ID] =" & a
End If
Next ctl
End Function
谢谢wnxjy68
互相学习,但能够唯一标识记录的字段如果是文本怎么办?
总记录:8篇 页次:1/1 9 1 :