有时候尝试完成最多 次要 会变成 主要 头痛......我在尝试解决此问题时,以某种方式损坏了数据库。现在我 真的 决心解决这个问题。 (我稍后会担心损坏的数据库!)
自动打开.accdb
文件时:
Last Update Date
Last Update Date
(必须对用户可见) Update Progress Message(s)
(必须对用户可见) Last Update Date
(必须对用户可见) 问题是 (must be visible to user)
的目标。
我无法在所有代码完成运行之前显示任何内容,无论我如何运行代码(包括:使用 File <将表单设置为自动打开) / kbd>→选项→Display Form
;添加AutoExec
宏来调用代码以打开表单并运行更新;或者,手动运行。)
我一直在尝试表格的开场活动,看看我是否错过了什么。
根据 Order of Events 文档:
使用表单上的数据
当您在表单中的记录之间移动并更改数据时,会发生表单和控件事件。例如,首次打开表单时,会发生以下事件序列:
Open
(表单)→Load
(表单)→Resize
(表单)→Activate
(表单)→Current
(表单)→{{ 1}}(控制)→Enter
(控制)
表格在任何时候都不会明显更新。我尝试添加Me.Repaint
,甚至尝试Echo=True
和DoEvents
,但显然他们没有改变任何内容。
我的测试代码:
GotFocus
打开表单的结果:
(请注意,表单的Private Sub Form_Open(Cancel As Integer)
txtTest = "Form_Open()": MsgBox "1. Form_Open"
End Sub
Private Sub Form_Load()
txtTest = "Form_Load()": MsgBox "2. Form_Load"
End Sub
Private Sub Form_Current()
txtTest = "Form_Current()": MsgBox "3. Form_Current"
End Sub
Private Sub txtTest_Enter()
txtTest = "txtTest_Enter()": MsgBox "4. txtTest_Enter"
End Sub
Private Sub txtTest_GotFocus()
Echo True : Repaint : DoEvents
txtTest = "txtTest_GotFocus()": MsgBox "5. txtTest_GotFocus"
End Sub
Private Sub txtTest_Change() : MsgBox "This Does't Run!" : End Sub
Private Sub Form_AfterUpdate() : MsgBox "This Does't Run!" : End Sub
Private Sub txtTest_Change() : MsgBox "This Does't Run!" : End Sub
Private Sub txtTest_BeforeUpdate(Cancel As Integer) : MsgBox "This Does't Run!" : End Sub
Private Sub txtTest_AfterUpdate() : MsgBox "This Does't Run!" : End Sub
和Activate
事件以及控件的AfterUpdate
,Change
和BeforeEvent
事件根本不会触发。 )子>
理论上,表单应该显示在AfterEvent
后面,但既不运行实际更新代码,也不运行“暂停”(使用MsgBox
循环)不会t显示表格。
我可以发誓我过去没有遇到任何问题,但无论我做什么,表单只会在所有代码完成后才会显示。< / p>
答案 0 :(得分:3)
您可以使用Form_Timer
事件来延迟执行,直到表单完全加载完毕。
Private Sub Form_Load()
Me.TimerInterval = 1 'Trigger 1 millisecond, but asynchronously from other tasks
'Triggers after AutoExec macro has finished
End Sub
Private Sub Form_Timer()
Me.TimerInterval = 0 'Trigger only once
'Your other tasks here
End Sub