Solved

Modal form does not show until it is finished.

Posted on 2011-09-15
11
486 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 48

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 48

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 48

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Suggested Courses
Course of the Month7 days, 6 hours left to enroll

623 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