Modal form does not show until it is finished.

My application has a data entry form. After the user enters the weekly data, he clicks a “return” button that returns him to the main “dashboard” – or not, depending on:

Sub cmdReturn_Click first shows a “sanity check” form – in modal mode so that the return button in the data entry form waits for the sanity checks. The Form_Load for the Sanity Check form calls five sanity check subroutines on the data. If any data errors are detected, a public boolean bErrors is set to True.

So far so good.

When I click “Return” on the data entry form, the Sanity Check form does NOT show on-screen until all five sanity checks are completed. THEN it shows.

Why is this? I would like the Sanity Check form to show first, THEN call the checking subroutines. I have a rather cute progress “how goes it” display there to soothe the user, and to display details of any errors found in the data.

As it is, he sees nothing until all the sanity checks are accomplished. Then the Sanity Check form appears, all finished.

Data Entry Form:

Public bErrors As Boolean

Sub cmdReturn_Click()
   bErrors = False
   frmSanityCheck.Show vbModal
   If bErrors = False Then
      Unload Me
   End If
End Sub

Open in new window

NormaPosyPhysicistAsked:
Who is Participating?
 
Brook BraswellConnect With a Mentor Application Development ManagerCommented:
One Step Further....

Put a Timer on your frmSanityCheck - perhaps name it tmrCheckSanity
In design set property  enabled = false

put a Global boolean of bLoaded also in your frmSanityCheck

in Form_Load...
bLoaded = false ' it is already false by default but I like to show what is going on..

in Form_Activate

If Not bLoaded then
   bLoaded = True
   tmrSanityCheck.Enabled = True
End If

' in your timer event
Private Sub tmrSanityCheck_Timer()
   tmrSanityCheck.Enabled = False
   ' CHECK FOR SANITY HERE
End Sub
0
 
Brook BraswellApplication Development ManagerCommented:
Do your Sanity Checks in the Form_Activate Event rather than the Form_Load event
0
 
Brook BraswellApplication Development ManagerCommented:
Also...it is a good practice to tell the modal form who is in charge :)
Public bErrors As Boolean

Sub cmdReturn_Click()
   bErrors = False
   frmSanityCheck.Show vbModal, me
   If bErrors = False Then
      Unload Me
   End If
End Sub

Open in new window

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Martin LissOlder than dirtCommented:
Put Me.Show early on in the frmSanityCheck Form_Load event.
0
 
NormaPosyPhysicistAuthor Commented:
MartinLiss:

Me.Show in the Form_Load event bombs back to the data entry form.

Brook1966:

Stepping through the code in Form Activate:
It gets to the bottom of

If Not bLoaded then
   bLoaded = True
   tmrSanityCheck.Enabled = True
End If

Then just sits there. (That's all the code in Form_Activate. The Sanity checks are called from the tmrSanityCheck, as you recommend.)

What is the thinking behind using the timer?
0
 
Martin LissOlder than dirtCommented:
Can you zip up and attach your project?
0
 
Brook BraswellApplication Development ManagerCommented:
The purpose of the timer is to allow the form to go ahead and show regardless of the checking code.
there are times when a process running in the activate event, prevents a form from finishing the paint of the screen in a timely manner.  The Timer begins it's own process independent of the form.  This is also a good method for some instances when dealing with Code in the Click event of a Combo box.

is the Timer Firing and your sanity check running in the example I gave ?

The bLoaded flag is so that you can have code in your activate event that only fires the first time the form is activated rather than every time it receives the focus.  Even a message box fired within a form will cause the activate event of a form to run.

0
 
NormaPosyPhysicistAuthor Commented:
It's a rather large project. I don't think sending the whole thing is a good idea. And parts of it are still under construction.

The little piece uner immediate consideration:

Form frmSanityCheck:

Public bLoaded as Boolean

Private Sub Form_Load()
   bLoaded = False
'   Me.Show
End Sub

Private Sub Form_Activate()
If Not bLoaded Then
   bLoaded = True
   tmrSanityCheck.Enabled = True
End If
End Sub

Private Sub tmrSanityCheck_Timer()
   tmrSanityCheck.Enabled = False
   DoTheSanityChecks
End Sub

Open in new window


NOTE 1:
In the Form_Load:

Me.Show is commented out. If it is uncommented, produces an error and bombs back to Data Entry form.

NOTE 2:

With Me.show commented out, the form shows ok. But:

Stepping through the code, it gets through the Form_Activate, but doesn't enter Sub tmrSanityCheck_Timer(). So the sub DoTheSanityChecks is never called.
0
 
Martin LissOlder than dirtCommented:
Enabling a form doesn't load it. You need to either Show (which also loads) or Load the form.
0
 
NormaPosyPhysicistAuthor Commented:
frmSanityCheck.Show was executed in the cmdReturn_Click sub.
See the code in my original posting. (Now appended by ", Me")
0
 
NormaPosyPhysicistAuthor Commented:
The interval property of the timer has to be greater than zero.
I set it to 100 milliseconds, and your solution works just fine.

Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.