簡體   English   中英

access 2003 中的色域

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM