Solved

Modal form does not show until it is finished.

Posted on 2011-09-15
11
440 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
 
LVL 45

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 45

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 45

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
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…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now