我在使用條件格式時遇到了類似的問題。當我碰到這個問題,我用兩種不同的方法解決它:
溝的條件格式,並通過代碼(即手動應用的格式,通過Form_Current事件,相關的控制的After_Update事件等)。顯然,如果您試圖區分連續綁定形式的控件,這將不起作用。在這些情況下,我會使用其他選項
手動添加和刪除條件格式本身。我不完全確定這是爲什麼會起作用,但它確實如此。我會給你一個快速示例功能,顯示該技術:
。
Private Const DefaultHLColor As Long = 10092543 'RGB(255, 255, 153); Light Yellow
'---------------------------------------------------------------------------------------
' Procedure : HighlightRow
' DateTime : 2/22/2008 3:27
' Author : Mike
' Purpose : Highlight the detail section of a continuous form.
' Usage : 1) Add a textbox bound to a unique field (preferrably the primary key)
' to a form set to continuous view.
' 2) Set Enabled = No, Locked = Yes, BackColor = {Detail Section BackColor},
' BackStyle = Normal, SpecialEffect = Flat, ForeColor = BackColor
' 3) Expand the textbox to fill the entire detail section, Send to Back.
' 4) Move it down one pixel ([Ctrl] + [{down arrow key}])
' 5) Add the following to the form's OnCurrent event:
' =HighlightRow([{TextBoxName}])
' Notes : We could simply Refresh the form in the OnCurrent event, but Access
' (2002, at least) does not have a rock solid implementation of conditional
' formatting. The problem with Refreshing the form occurs when we select
' a record (which gets highlighted), then we scroll the form so the
' highlighted record is no longer visible, then select a new record, and
' scroll back to the previous record to see that, sadly, it is still
' highlighted.
'---------------------------------------------------------------------------------------
'
Function HighlightRow(Ctl As TextBox, Optional HLColor As Long = DefaultHLColor) 'vv
On Error GoTo Err_HighlightRow
Application.Echo False
With Ctl
.FormatConditions.Delete
If Ctl.Parent.CurrentRecord <> 0 Then
If Not IsNull(.Value) And Not IsEmpty(.Value) Then
If IsNumeric(.Value) Then
.FormatConditions.Add acFieldValue, acEqual, .Value
Else
.FormatConditions.Add acFieldValue, acEqual, """" & .Value & """"
End If
.FormatConditions(0).BackColor = HLColor
.FormatConditions(0).ForeColor = HLColor
.FormatConditions(0).Enabled = False
End If
End If
End With
Exit_HighlightRow:
Application.Echo True
Exit Function
Err_HighlightRow:
LogError Err.Number, Err.Description, "HighlightRow"
Resume Exit_HighlightRow
End Function
兩個想法......文本框中是否有其他事件(非鼠標),如OnCurrent?而且,你是否嘗試過使用不同的觸摸屏(或將窗口移到其他地方)?也許有一些錯誤/卡在屏幕上,它變得「幸運」並在某處激活控件。 – BIBD 2011-01-21 16:37:37
應用程序凍結時的CPU負載是多少? Maxed出或不? – HansUp 2011-01-21 17:22:13
您的應用程序是否在任何地方設置了Echo或SetWarnings? – HansUp 2011-01-21 17:26:46