简体   繁体   English

access 2003 中的色域

[英]Color field in access 2003

On MS-Access 2003 i've a mask that shows results of a query.在 MS-Access 2003 上,我有一个显示查询结果的掩码。 For example result of query is:例如查询结果是:

Column1 Column2列 1 列2

1 Y 1 Y

2 N 2 N

3 N 3 N

4 Y 4

It shows in the mask ad a table.它在掩码广告中显示了一个表格。 I need to color background field of column2 if the value is Y. To do that i've use the code:如果值为 Y,我需要为 column2 的背景字段着色。为此,我使用了以下代码:

Private Sub Form_Current()
    if (Column2) = "Y" Then
        Stato.BackColor = vbGreen
    End If
End Sub

But it colored all background.但它为所有背景着色。 So i've tried a workaround:所以我尝试了一种解决方法:

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

But this also colored all bg.但这也给所有 bg 上色。 Some suggestion?一些建议?

You can add conditional formatting in code using something like this.您可以使用这样的方法在代码中添加条件格式。 This function is based on some code I've used and you may need to tweek it to fit your specific requirements.此函数基于我使用过的一些代码,您可能需要对其进行调整以满足您的特定要求。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM