Wait while form renders

  • Thread starter Thread starter Todd Lemen
  • Start date Start date
T

Todd Lemen

I have a form that needs to update data on open. This
takes some time. When the user opens this form by
clicking a command button on a switchboard, I would like
to display a second form, the detail section of which
carries a label reading, "Please wait while I update the
records...". The idea is for this second form to
display, run a query that updates the data, then open the
input form and close.
Problem is, as soon as the query engages, the render
stops. The user sees the border of this "please wait"
window, then sees the input form when the query is
finished. Never sees the detail section with the
message...
Is there another method for this that I can use? How
would I hold off running the query until this simple
message form renders?

Thanks,
Todd Lemen
 
If I am reading your process correctly, the user clicks a
button on a switchboard which opens a form (call it
FormA). FormA has code in its Open or Load event that
runs an time intensive query. Once the query is done,
FormA closes and the data entry form appears.
If this is indeed your process, I would suggest the
following:
1) When the user clicks your switchboard button, have it
launch Code not a form.
2) Within the code: open FormA, run your query, open
FormB, close FormA-- in that order.

That should do what you want. You may want to make FormA
a pop-up and modal as well.
 
strForm = "MyFormName"
DoCmd.OpenForm strForm, acNormal
Call WaitUntilOpen(strForm, acForm)
....run your query

Note: the following 2 routines could easily be combined into 1 piece of code
but WaitUntilOpen is only one of several things that uses IsLoaded, so I
keep them separate.

Public Sub WaitUntilOpen(strObjName As String, Optional lngObjType As
acObjecttype = acForm)
' Suspends code execution until object is open. Default ObjectType is a
Form.
On Error Resume Next
Do Until IsLoaded(strObjName, lngObjType)
DoEvents
Loop
End Sub

Public Function IsLoaded(strObjName As String, Optional lngObjType As
acObjecttype = acForm) As Boolean
' Returns True if strName is Open (non-zero), False(0) otherwise.
' Should return 0, not an error, if the object doesn't exist
' Default ObjectType is Form
On Error Resume Next
IsLoaded = (SysCmd(acSysCmdGetObjectState, lngObjType, strObjName) <> 0)
End Function

HTH,
 
You might try
Me.Repaint
to finish painting your form
Then run the query.
Are all of your criteria fields for the query indexed?
That can speed up its execution significantly.

HTH
- Turtle
 
Thank you! Here is the sequence that I found to be
effective:
Open FormA
Close Switchboard
Repaint FormA
Run Query
Open Form B
Close Form A

I did find it necessary to repaint FormA. Without the
repaint, the previous screen image (in this case, the
Switchboard) appears in the detail section of FormA, as
if FormA were an image mask...

TL
 
Back
Top