访问条件格式-用户界面上的VBA选项更少? [英] Access Conditional Formatting - Fewer VBA Options over user interface?
本文介绍了访问条件格式-用户界面上的VBA选项更少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题是,虽然前端允许4个或更多条件,但当我尝试使用VBA设置条件时,在设置第四个条件时遇到错误。换句话说,如果我只尝试在代码中设置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
当CATEGORY表中包含4条记录时:即tblTestConditionalFormatting,我收到以下错误:
"运行时错误7966:您指定的格式条件大于格式条件数。"
那么,似乎存在一个错误,即前端可以处理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
编辑
如果您不触摸0..2:,显然您可以编辑FormatConditions>=3 https://access-programmers.co.uk/forums/showthread.php?t=271679
也许我有这样的东西...:/
这篇关于访问条件格式-用户界面上的VBA选项更少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文