Solved

Modal form does not show until it is finished.

Posted on 2011-09-15
11
465 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

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 47

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 47

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

756 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