Solved

Modal form does not show until it is finished.

Posted on 2011-09-15
11
458 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:NormaPosy
  • 4
  • 4
  • 3
11 Comments
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 36544639
Do your Sanity Checks in the Form_Activate Event rather than the Form_Load event
0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 36544641
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
 
LVL 14

Accepted Solution

by:
Brook Braswell earned 500 total points
ID: 36544674
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 46

Expert Comment

by:Martin Liss
ID: 36545821
Put Me.Show early on in the frmSanityCheck Form_Load event.
0
 

Author Comment

by:NormaPosy
ID: 36546627
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
 
LVL 46

Expert Comment

by:Martin Liss
ID: 36546659
Can you zip up and attach your project?
0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 36548724
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
 

Author Comment

by:NormaPosy
ID: 36552373
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
 
LVL 46

Expert Comment

by:Martin Liss
ID: 36552445
Enabling a form doesn't load it. You need to either Show (which also loads) or Load the form.
0
 

Author Comment

by:NormaPosy
ID: 36552862
frmSanityCheck.Show was executed in the cmdReturn_Click sub.
See the code in my original posting. (Now appended by ", Me")
0
 

Author Closing Comment

by:NormaPosy
ID: 36552913
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question