访问条件格式 - 用户界面上的 VBA 选项更少?

Access Conditional Formatting - Fewer VBA Options over user interface?

问题是,虽然前端允许 4 个或更多条件,但当我尝试使用 VBA 设置条件时,我 运行 在设置第 4 个条件时出错。换句话说,如果我只尝试在代码中设置 3 个条件,那么代码就可以正常工作。

我正在使用 MS Access 2010。我需要为连续表单上的两个文本框设置条件格式。我知道旧版本的 MS Access 在文本框上只允许 3 个条件,但我知道我可以在 Access 2010 中获得更多条件。我当前的应用程序使用用户界面有 4 个条件。在我对这个问题的研究中,有人说更高版本的 MS Access 最多允许 50 个条件。我无法以任何一种方式确认这一点,即使我查看了 Access 2010 规范页面也是如此。但是我知道我至少可以拿到3个以上的条件

以下是最多适用于 3 条记录的测试代码:

Function fApplyConditionFormatNow()

Dim objFormatConds As FormatCondition
Dim i As Integer 'index number for specific format conditions
Dim stSQL As String 'query to get list of categories
Dim rs As DAO.Recordset

i = 0

'clear out just in case FormatConditions accidentially got saved
'with the form at some point.
Me.ID.FormatConditions.Delete

'get a recordset containing the formatting information
'(ie, get RGB values for each category type)
stSQL = "SELECT * FROM tblTestConditionalFormatting;"
fRunSQL stSQL, rs 'fRunSQL is custom code that gets runs stSQL and returns the recordset

'loop through recordset to get conditional formatting values
Do Until rs.EOF
    'create a condition on textbox named "ID".  The condition will be for
    'the Category/Type (TypeNm) that's up now in the recordset.
    Set objFormatConds = Me.ID.FormatConditions.Add(acExpression, , "[TypeNm] = '" & rs!TypeNm & "'")
    'add formatting for the condition just created.
    With Me.ID.FormatConditions(i)
        .BackColor = RGB(rs!RGB1, rs!RGB2, rs!RGB3)
    End With
    i = i + 1
    rs.MoveNext
Loop

rs.Close
Set rs = Nothing

End Function

当类别 table 中包含 4 条记录时:即 tblTestConditionalFormatting,出现以下错误: "Runtime error 7966: The format condition you specified is greater than the number of format conditions."

那么,前端可以处理3个以上的条件,而VBA对象只能处理3个条件,这似乎是一个错误?或者也许我做错了什么。还有其他人遇到过这个吗?您有变通办法吗?

谢谢!!

而不是 With Me.ID.FormatConditions(i),使用您刚刚创建的 FormatCondition 对象:

Set objFormatConds = Me.ID.FormatConditions.Add(acExpression, , "[TypeNm] = '" & rs!TypeNm & "'")
'add formatting for the condition just created.
With objFormatConds 
    .BackColor = RGB(rs!RGB1, rs!RGB2, rs!RGB3)
End With

您不再需要 i

我有类似的代码(简化)如下:

For i = 1 To 6
    lColor = DLookup("Color", "someTable", "p_Color_ID = " & i)
    Set objFrc = txtFld.FormatConditions.Add(acExpression, , "[ColorGroup] = '" & i & "'")
    objFrc.BackColor = lColor
Next i

编辑

显然你可以编辑 FormatConditions >= 3 如果你不碰 0..2:
https://access-programmers.co.uk/forums/showthread.php?t=271679

也许我有这样的东西...... :/