访问表单没有出现,但是过程正在运行

问题描述 投票:0回答:2

我有一个标题为frmReportMetrics的Access表单,该表单作为显示表单打开。打开时,它使用UserIsInGroup()验证权限。如果用户不在指定的组中,则Select Case-Case False语句将关闭frmReportMetrics并打开frmAccessDenied,这只是一个停车标志图像,其文本会警告个人他们无权使用该应用程序。

'Set default values to form items
Private Sub Form_Open(Cancel As Integer)
'Check to assure user has privileges to run front-end
    Select Case UserIsInGroup("The Reports")
        Case False
            DoCmd.Close acForm, Me.Name, acSaveNo
            DoCmd.OpenForm "frmAccessDenied", acNormal, "", "", , acNormal
            Exit Sub
    End Select
    Me.lblTabGoToManagersReportsPage.Visible = False

'Only display the label if the user is a member of the security group
    Select Case UserIsInGroup("The Reports - Managers")
        Case True
            Me.lblTabGoToManagersReportsPage.Visible = True
    End Select
End Sub

然后,我希望该应用在显示倒数5秒后自动关闭。所以我在frmAccessDenied

中使用了pause()
Private Sub Form_Activate()

    Me.lblClosingIn.Caption = "This form will close in 5 seconds"
    Pause (1)
    Me.lblClosingIn.Caption = "This form will close in 4 seconds"
    Pause (1)
    Me.lblClosingIn.Caption = "This form will close in 3 seconds"
    Pause (1)
    Me.lblClosingIn.Caption = "This form will close in 2 seconds"
    Pause (1)
    Me.lblClosingIn.Caption = "This form will close in 1 seconds"
    Pause (1)
    Application.Quit

End Sub

我确定它可能会更短...

问题是进行测试时,我退出了AD安全组,并打开Access前端,frmAccessDenied表单未按预期弹出,但该应用确实在5秒钟内退出。我也从未看到过frmReportMetrics。我已经在frmAccessDenied中尝试过_Load,_Open,_Activate和_Current,但是它们都不允许出现frmAccessDenied。 _GoftFocus正常工作,并且出现frmAccessDenied,并且我看到了停止标志和警报,但是倒计时没有继续,并且该应用程序在5秒钟内没有退出。

当我逐步通过frmAccessDenied时,我可以随时重置,并且出现frmAccessDenied,并且我在底部看到带有警报的停止标志以及相应的Me.lblClosingIn.Caption,并且如果我一直通过该应用程序,则退出。enter image description here

我在某种程度上缺少Exit Sub之类的东西吗?还是应该使用什么事件程序?

UserIsInGroup()和pause()均按预期工作,分别感谢@Nigel Heffernan和@Steve Mallory

TIA,蒂姆

PS @Erik A,我到处都添加了DoEvents,但仍未绘制frmAccessDenied。

Private Sub Form_Activate()
    DoEvents

    Dim I As Integer
    Dim sFirstPart As String
    Dim sSecondPart As String
    Dim sCompleteSentence As String

    sFirstPart = "This form will close in "
    sSecondPart = " seconds!"

    For I = 5 To 2 Step -1
        sCompleteSentence = sFirstPart & I & sSecondPart
        DoEvents
        Me.lblClosingIn.Caption = sCompleteSentence
        Pause (1)
    Next
    DoEvents
    Me.lblClosingIn.Caption = "This form will close in 1 second!"
    Pause (1)
    'Application.Quit
    DoEvents
    Me.lblClosingIn.Caption = "This form will close in 5 seconds"
    Pause (1)
    DoEvents
    Me.lblClosingIn.Caption = "This form will close in 4 seconds"
    Pause (1)
    DoEvents
    Me.lblClosingIn.Caption = "This form will close in 3 seconds"
    Pause (1)
    DoEvents
    Me.lblClosingIn.Caption = "This form will close in 2 seconds"
    Pause (1)
    DoEvents
    Me.lblClosingIn.Caption = "This form will close in 1 second"
    Pause (1)
    'Application.Quit
End Sub

而且我尝试了For Next,但这也无济于事。

当我调试并运行_Open,_Load,_Activate和_Current且每个都有断点时,frmAccessDenied从不可见。我什至尝试了DoEvents的自由应用!

Option Compare Database
Option Explicit

Private Sub Form_Activate()
    DoEvents
    Me.txtMessage.Value = "This application will close in 3 seconds!"
End Sub

Private Sub Form_Current()
    DoEvents
    Me.txtMessage.Value = "This application will close in 2 seconds!"
End Sub

Private Sub Form_Load()
    DoEvents
    Me.txtMessage.Value = "This application will close in 4 seconds!"
End Sub

Private Sub Form_Open(Cancel As Integer)
    DoEvents
    Me.txtMessage.Value = "This application will close in 5 seconds!"
End Sub

当表单最终弹出时,其值为“此应用程序将在2秒内关闭!”

我想念什么?

Voila! @汤姆·罗宾逊!这是理解Access的内部原理的一个不错的小工具。该窗体虽然已创建,但直到Access使它可见或直到您使其可见为止,它才可见。我继续进行操作,并在_Open和_Load的倒数计时中显示了表格。符合规格!

Option Compare Database
Option Explicit
Private Sub Form_Load()
Dim i As Integer
Dim txtFirstPart As String
Dim txtSecondPart As String
txtFirstPart = "This application will close in "
txtSecondPart = " seconds!"
For i = 5 To 2 Step -1
    Me.txtMessage.Value = txtFirstPart & i & txtSecondPart
    Pause (1)
Next
Me.txtMessage.Value = "This application will close in 1 second!"
Pause (1)
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
Private Sub Form_Open(Cancel As Integer)
    Me.Visible = True
End Sub
ms-access access-vba ms-access-forms
2个回答
1
投票

Me.Visible = True添加为Form_Activate的第一行。

默认情况下,新打开的表单在各种表单事件完成之前不会显示。这样一来,用户就不会看到分散注意力的启动活动。


2
投票

由于您的子程序是同步运行的,因此它不会给Access时间显示表单,因为您的代码会在绘制表单之前运行。

要变通解决此问题,请以DoEvents()开头,然后在更改表单内容后重复进行。

或者,您可以使用_Timer倒数并关闭表格,而不会导致应用程序无响应。

© www.soinside.com 2019 - 2024. All rights reserved.