Code Causes Task Manager to Max Out

T

Tom \T\

Hello Everyone,

This code is contained within a Command button. The Command button is on an
Unbound Form. The Unbound Form allows the user to enter parameters into a
query in which a Report is based. The Command Button Previews a Report.

While SysCmd(acSysCmdGetObjectState, acReport, stDocName) = acObjStateOpen
Me.Visible = False
DoEvents
Wend
Me.Visible = True
If Err = 2501 Then
Err.Clear
End If

When the Report is displayed and the Unbound Form is set to Me.Visible =
False the Task Manager is maxed out. I know this because I commented out the
above code, compiled and then saved the code. I then previewed the report
and the Task Manager remained low.

I like the ability to hide the form but how can it be modified so that it
does not max out Task Manager.

Any help would be greatly appreciated.

Tom "T"
 
A

Allen Browne

The code runs a loop that continues whileever the report is open. Even
though it includes a DoEvents to yield processor time to other
threads/tasks, the code is continually looping, so naturally it will consume
any spare processor cycles and keep the CPU busy.

Instead of constantly looping, would it be possible to simply set the form's
Visible property to No in the Open event of the report, and set it to Yes
again in the report's Close event?
 
T

Tom \T\

Allen,

Thank You. I tried exactly what you said and it works! Happy New Year!

Tom "T"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top