[英]Color field in access 2003
在 MS-Access 2003 上,我有一个显示查询结果的掩码。 例如查询结果是:
列 1 列2
1 Y
2 N
3 N
4岁
它在掩码广告中显示了一个表格。 如果值为 Y,我需要为 column2 的背景字段着色。为此,我使用了以下代码:
Private Sub Form_Current()
if (Column2) = "Y" Then
Stato.BackColor = vbGreen
End If
End Sub
但它为所有背景着色。 所以我尝试了一种解决方法:
For Each ctl In Me.Section(acDetail).Controls
If (ctl) = Column2 Then
If (Me.Column2) = "Y" Then
ctl.BackColor = QBColor(2)
End If
End If
但这也给所有 bg 上色。 一些建议?
您可以使用这样的方法在代码中添加条件格式。 此函数基于我使用过的一些代码,您可能需要对其进行调整以满足您的特定要求。
Dim fcd As FormatCondition
Dim ctl As control
Dim frm As Form
Dim txt As TextBox
Dim strCond As String
For Each ctl In frm.Controls
If TypeOf ctl Is Access.TextBox Then
If ctl.Visible = True Then
Set txt = ctl
If txt.Name = "Column2" Then
strCond = "=Y"
Set fcd = txt.FormatConditions.Add(acExpression, acEqual, strCond)
fcd.BackColor = QBColor(2)
End If
End If
End If
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.