MS Access 2010 - 分割形式闪烁[条件格式]

时间:2016-07-18 13:49:48

标签: vba ms-access access-vba ms-access-2010 access

问题

一切都运行得很好,然后我在表单体(和数据表)中添加了两个字段:" Impact"和"兴趣"。我将它们设置为条件格式,这样如果它们包含文本" red",它们会有红色填充。

当表单加载时,条件格式会立即应用于数据表视图中的第一个条目,并且需要一秒钟才能应用于其他两个条目我将"黄色&# 34;和"绿色" in(分别具有黄色和绿色填充)。如果我在表单加载时设置了第三个条目,那么这个条目会立即将格式应用到数据表视图中。 MS Access表示它是"计算",当这完成后,将应用条件格式。

除此之外,当应用第一个文本过滤器时,表单正文文本框"影响"和"兴趣"闪烁,以及标题中的第二个文本过滤器和" forename"数据表视图中所选条目的位置(我的VBA代码在应用过滤器后选择了forename)。当我移动鼠标时,闪烁停止并且过滤器适用。但有时闪烁并不会发生。 这是因为我添加了"影响"和"兴趣"字段,带条件格式。

这是我表单的基本结构

表格标题: 几个按钮和两个文本框。用户输入搜索字词,然后点击"应用过滤器"按钮缩小数据表视图中显示的数据。

数据表视图: 关键列是可见的,当用户点击其中时,它的个人资料会显示在表单中。

表单正文:包含数据表中的数据,按类别列出。

这是我的表单加载时的代码 - 它会加载所有相关数据,设置一个复选框,并将焦点设置在第一个文本过滤器上:

Private Sub Form_Load()

Me.RecordSource = "SELECT * FROM Staff "
CheckImpInt.Enabled = True
CheckImpInt = False
StaffTotalSearchText1.SetFocus

End Sub

这是第一个过滤按钮的代码:

Private Sub Filter1Button_Click()

If CheckImpInt = True Then

Me.RecordSource = "SELECT * FROM Staff " & _
"WHERE [Interest] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
   "Or [Impact potential] Like '*" & Me![StaffTotalSearchText1] & "*'"

Else

Me.RecordSource = "SELECT * FROM Staff " & _
"WHERE [Forename] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
   "Or [Surname] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
   "Or [Position] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
   "Or [Group] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
   "Or [Division] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
   "Or [All groups] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
   "Or [Expertise] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
   "Or [Institutes] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
   "Or [Roles] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
   "Or [skills - analysis] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
   "Or [skills - compute] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
   "Or [Notes] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
   "Or [Paired IC] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
   "Or [Paired Company?] Like '*" & Me![StaffTotalSearchText1] & "*' "

End If

End Sub

1 个答案:

答案 0 :(得分:0)

我不确定为什么在FormLoad事件中设置了recordiurce - 看起来它仍然是相同的 - 除了过滤器。

我建议

  • 将表单的记录源设置为[Staff],并从Me.RecordSource = "SELECT * FROM Staff"事件中删除Form_Load
  • 将您的filter_button事件更改为使用过滤器而不是使用recordsource

更新FilterButton_Click子

Private Sub Filter1Button_Click()  
    If CheckImpInt = True Then

        Docmd.ApplyFilter , "[Interest] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
           "Or [Impact potential] Like '*" & Me![StaffTotalSearchText1] & "*'"

    Else

        Docmd.ApplyFilter , "[Forename] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
           "Or [Surname] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
           "Or [Position] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
           "Or [Group] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
           "Or [Division] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
           "Or [All groups] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
           "Or [Expertise] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
           "Or [Institutes] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
           "Or [Roles] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
           "Or [skills - analysis] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
           "Or [skills - compute] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
           "Or [Notes] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
           "Or [Paired IC] Like '*" & Me![StaffTotalSearchText1] & "*'" & _
           "Or [Paired Company?] Like '*" & Me![StaffTotalSearchText1] & "*' "

   End If

End Sub

如果将这两个过滤器移动到实际查询中,您也会获得更好的性能 - 然后将ApplyFilter更改为使用Where参数而不是Filter,但这完全不同。

最后,如果要完全删除闪烁,可以在应用过滤器之前添加行以停止屏幕更新 - 然后在子结束时将其打开。

切换屏幕更新

在if块之前添加Application.Echo False 在if块

之后添加Application.Echo True