我希望在执行VBA代码时停止闪烁我的表单,但Application Echo无效。
我在Combobox_After_Update事件中有这段代码:
Private Sub Combo11_AfterUpdate()
'Stop flickering
Application.Echo False
On Error Resume Next
'If User deletes Combo Item, then delete record
If IsNull(Combo11) Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
End If
'Call code for re-positioning controls on form
Call MovingAllControls
'Close and reopen form
Call ReOpen
Application.Echo True
End Sub
被叫程序(可能是闪烁的原因):
Sub MovingAllControls
'Refresh
DoCmd.Requery
Const MaxRecs As Integer = 10
Dim NumRecs As Integer
On Error Resume Next
'find last record in subform and then expand Detail section according to number 'of records
With Forms![MyForm]![MySubform].Form
.Recordset.MoveLast
NumRecs = .RecordsetClone.RecordCount
If NumRecs > MaxRecs Then NumRecs = MaxRecs
.InsideHeight = NumRecs * .Section(0).Height + 350
End With
'Moving all controls under subform - in this example only one, but in reality I 'have plenty controls to move on form
Forms![MyForm]![FieldName].Top = Forms![MyForm]![Myubform].Top + Forms![MyForm]![MySubform].Form.InsideHeight + 1100
End Sub
从Combobox_After_Update事件中调用的另一个过程:
Sub ReOpen()
'I reopen form, because this is only way my subform controls moves as they 'should - dynamically
DoCmd.Close acForm, "MyForm"
DoCmd.OpenForm "MyForm"
End Sub
我还试图看看在After_Update_event中产生了什么错误,并且我收到错误“424 - object required”,但是我的代码很简单,只有问题是控件闪烁。还有其他方法可以阻止闪烁,或者我的代码出了什么问题?
感谢您的帮助!!
答案 0 :(得分:1)
而不是Application.Echo False
,请尝试Form.Painting
方法:
' code under form
Me.Painting = False
' do actions that cause flicker
Me.Painting = True
Me.Repaint
另外,在这里查看您的代码:
DoCmd.Close acForm, "MyForm"
DoCmd.OpenForm "MyForm"
我会说这是不好的做法:
Form_Open
或Form_Close
等事件,则可能会在首次打开表单时重新运行仅运行一次的代码,从而导致错误。Access中始终有一种方法可以获得所需的结果,而无需关闭/重新打开表单。