我有一个自定义的Popup,只要一个活动需要超过一秒钟,我就会调用它。示例:
PopupMsg("Getting records")
它创建了一个很好的框,只显示用户正在发生的事情,然后在活动完成后它会悄然消失。
它适用于只需要大约3秒钟的任何事情,但除此之外,它会消失,然后用户会留下活动结束的印象。我想让它与任何正在发生的活动一样长时间熬夜,但我从来没有成功地确定这一点。我想确保在弹出窗口消失之前完成所有屏幕计算。
这是我如何实现我的PopupMsg例程
Public Function PopUpMsg(strMsg As String, Optional strTitle As String)
Dim frmWait As New Form_Wait
If strTitle <> "" Then
frmWait.OpenForm strMsg & "...", strTitle
Else
frmWait.OpenForm strMsg & "..."
End If
End Function
等待(一个名为&#39;等待&#39;包含以下代码的表单)
Option Compare Database
Option Explicit
Public Property Let Message(ByVal MessageText As String)
Me.MessageLabel.Caption = MessageText
Me.Repaint
End Property
Public Property Get Message() As String
Message = Me.MessageLabel.Caption
End Property
Public Property Let Title(ByVal TitleText As String)
Me.Caption = TitleText
End Property
Public Property Get Title() As String
Title = Me.Caption
End Property
Public Function OpenForm(Optional MessageText As Variant, _
Optional TitleText As Variant) As Boolean
If Not IsMissing(MessageText) Then Me.MessageLabel.Caption = MessageText
If Not IsMissing(TitleText) Then Me.Caption = TitleText
Me.Visible = True
Me.Repaint
OpenForm = True
End Function
答案 0 :(得分:0)
当你通过类实例化打开一个表单时,它实际上并不存在,并且一旦Access决定进行垃圾收集并且看不到对表单的引用就会被删除。如果您希望表单在代码执行完成之前一直存在,最好的方法是传回该表单:
Public Function PopUpMsg(strMsg As String, Optional strTitle As String) As Object
Set PopUpMsg = New Form_Wait
If strTitle <> "" Then
PopUpMsg.OpenForm strMsg & "...", strTitle
Else
PopUpMsg.OpenForm strMsg & "..."
End If
End Sub
其余代码仍然有效
您可以这样称呼它:
Dim WaitForm As Object
Set WaitForm = PopupMsg("Getting records")
这样,您仍然依赖于垃圾收集来删除表单,但是一旦调用它的函数完成它就会关闭。
您也可以通过DoCmd.OpenForm "Wait"
打开表单,通过Forms
集合引用该表单,然后在功能结束时使用DoCmd.Close acForm, "Wait"
将其关闭,但之后您将拥有该表单积极地关闭它。该方法的完整代码:
Public Function PopUpMsg(strMsg As String, Optional strTitle As String)
DoCmd.OpenForm "Wait"
Dim frmWait As Form
Set frmWait = Forms!Wait
If strTitle <> "" Then
frmWait.OpenForm strMsg & "...", strTitle
Else
frmWait.OpenForm strMsg & "..."
End If
End Sub
称之为:PopupMsg("Getting records")
在执行结束时关闭它:DoCmd.Close acForm, "Wait"
如果您未在代码中调用DoEvents
,则还有另一种选择:
使用DoCmd.OpenForm "Wait"
打开表单,将TimerInterval
设置为1
,然后将DoCmd.Close acForm, Me.Name
添加到Form_Close
事件