Friday, June 24, 2005


Rule 15: Screen Updating

There is a flag Application.ScreenUpdating that can be set to True or False.

Setting it to False whilst building up code makes the application run faster.

However, in order to write code where you can nest calls means that each subroutine has to remember the state of the flag, and reset it when you exit the subroutine. If there is an early exit, or exception, the flag will not be restored.

One possible solution is a utility subroutine that keeps a stack of the values. Its certainly easier than maintaining flags by hand.

However, there is another approach. Just set the flag in the button code. That will always be at the top level so only one flag is needed. Just make sure its caught in the case of errors.

Private Sub CommandButton1_Click()
Dim su As Boolean
su = Application.ScreenUpdating
Application.ScreenUpdating = False
On Error GoTo finish
' Do some work here
Application.ScreenUpdating = su
Exit Sub
Application.ScreenUpdating = su
End Sub

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]