My "Please Wait" form blackens the rest of the screen (1 Viewer)

Bennet

New member
Local time
Today, 18:13
Joined
May 23, 2020
Messages
13
Hi everyone,

For about ten years I have had a "Please wait" style form that I use to keep the user informed when they are waiting for some long running operation to be completed.

Untitled.png


I might update this multiple times during a process.
"Downloading results"
"Calculating totals"
"Reticulating splines"
etc.

Public Function PleaseWait(PleaseWaitText As String)

[Forms]![XFrmPleaseWait].Visible = True
[Forms]![XFrmPleaseWait].[LblCurrent].Caption = PleaseWaitText

DoEvents ' prevent black screens
Forms.XFrmPleaseWait.Repaint

End Function


So I am calling PleaseWait multiple times during long operations. Each time my PleaseWait routine is called, the text is updated and I repaint the form to make sure the update is seen, and this has worked flawlessly for a long, long time.

Starting at some point in the last year maybe, when using this function, the whole of the rest of the application will now to go a black screen, and only the "Please Wait" form would show against a black background. To resolve this, I added a "DoEvents" immediately prior to the repaint which fixed the issue.

However, DoEvents is having other undesirable consequences. Specifically it seems to be causing Form_Timer events to fire which are meant to be paused by the ongoing process.

So my question is - is there anything else I can replace DoEvents with which will prevent black screens, but not cause the rest of the application to actually run any other code?
 

Ranman256

Well-known member
Local time
Today, 13:13
Joined
Apr 9, 2015
Messages
4,337
Why not just show a hidden label on the form? “Processing...” or other
it’s in the same form as the event, so it knows when the event is over.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:13
Joined
May 7, 2009
Messages
19,245
if there are Timer events to another form, you will need to "disable" them first.
you may call DisableAllTimers() first when your "please wait" form opens for the first time.
and call EnableAllTimers() when you close/hide it.
Code:
Option Compare Database
Option Explicit

' arnelgp
Dim collFormNames As Collection
Dim collTimerIntervals As Collection

Public Sub DisableAllTimers(ByVal thePleaseWaitFormName As String)
Dim i As Integer
Set collFormNames = New Collection
Set collTimerIntervals = New Collection
' loop through all open forms and disable the timers
For i = 0 To Forms.Count - 1
    If Forms(i).Name <> thePleaseWaitFormName And Forms(i).TimerInterval <> 0 Then
        collFormNames.Add i
        collTimerIntervals.Add Forms(i).TimerInterval
        'temporarily stop the timer
        Forms(i).TimerInterval = 0
    End If
Next
End Sub

Public Sub EnableAllTimers()
Dim i As Integer
For i = 1 To collFormNames.Count
    Forms(collFormNames.Item(i)).TimerInterval = collTimerIntervals.Item(i)
Next
Set collFormNames = Nothing
Set collTimerIntervals = Nothing
Next
End Sub
 

Bennet

New member
Local time
Today, 18:13
Joined
May 23, 2020
Messages
13
if there are Timer events to another form, you will need to "disable" them first.
you may call DisableAllTimers() first when your "please wait" form opens for the first time.
and call EnableAllTimers() when you close/hide it.
Perfect! I love this. Thank you!

(Is there any particular reason not to just do this?):

DisableAllTimers
DoEvents
EnableAllTimers
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:13
Joined
May 7, 2009
Messages
19,245
when you disable all timers, your DoEvents on your "please wait" form will work without
triggering any timer. so you can keep the DoEvents there and prevent black-screen.
 

Users who are viewing this thread

Top Bottom