Suspend Screen Painting During Form Updates

whdyck

Registered User.
Local time
Today, 01:56
Joined
Aug 8, 2011
Messages
169
I have some VBA code that does a recalc on a grandparent form, then restores the record displayed in a parent form to a bookmarked record, as follows:

Private Sub Form_AfterUpdate()
Dim strBookMark As String

strBookMark = Parent.Bookmark
Me.Recalc
Me.Parent.Parent.Recalc
DoCmd.GoToRecord , , acNewRec
Parent.Bookmark = strBookMark
End Sub

All the above code causes the screen to flash as it proceeds through the updates. I'd like the screen updates to happen all at once (i.e., to hide the interim results and only change the screen once to display the final result).
I saw somewhere else that this can be accomplished using commands like
DoCmd.Echo False
Me.Painting = False/True
Application.Echo False
I've tried to wrap the above code in various forms of the above, but I have seen no impact on the screen painting behavior.

Can this be done?

Thanks for any help you can give.

Wayne
 
For a form the painting property should do the trick. To disable all screen output we have the echo command.
Code:
Private Sub Form_AfterUpdate()
   Dim strBookMark As String   'currently no errorhandler defined.

   [COLOR="Blue"]me.painting = false[/COLOR]
   [COLOR="Red"]echo false[/COLOR]
   DoCmd.Hourglass (True) 'added this to show there is something running.

   strBookMark = Parent.Bookmark
   Me.Recalc
   Me.Parent.Parent.Recalc
   DoCmd.GoToRecord , , acNewRec
   Parent.Bookmark = strBookMark

   [COLOR="blue"]me.painting = true[/COLOR]
   [COLOR="red"]echo true[/COLOR]
   DoCmd.Hourglass (False)

End Sub

If this code errors out in one of the steps before the reset of the echo or me.painting you will end up without a usable screen update so a errorhandler should be there. For this code sample a simple "On error resume next" in the first line of the function should do the trick.
 
You can probably achieve this with:

Code:
Application.Screenupdating = False

before your update code.

And then use:

Code:
Application.Screenupdating = True

after the code has finished.

Hope this helps.

- Mike
 
You can probably achieve this with:

Code:
Application.Screenupdating = False

before your update code.

And then use:

Code:
Application.Screenupdating = True

after the code has finished.

Hope this helps.

- Mike

This must be for a later version of Access. I get the following compile error:
"Method or data member not found."
 
For a form the painting property should do the trick. To disable all screen output we have the echo command.
Code:
Private Sub Form_AfterUpdate()
   Dim strBookMark As String   'currently no errorhandler defined.
 
   [COLOR=blue]me.painting = false[/COLOR]
   [COLOR=red]echo false[/COLOR]
   DoCmd.Hourglass (True) 'added this to show there is something running.
 
   strBookMark = Parent.Bookmark
   Me.Recalc
   Me.Parent.Parent.Recalc
   DoCmd.GoToRecord , , acNewRec
   Parent.Bookmark = strBookMark
 
   [COLOR=blue]me.painting = true[/COLOR]
   [COLOR=red]echo true[/COLOR]
   DoCmd.Hourglass (False)
 
End Sub

If this code errors out in one of the steps before the reset of the echo or me.painting you will end up without a usable screen update so a errorhandler should be there. For this code sample a simple "On error resume next" in the first line of the function should do the trick.

If I add the code pieces you suggested, it fails to return to the bookmarked record on the parent form. If I then remove the Error-handling command, I see the following error:
Run-time error '3159':
Not a valid bookmark.

So it appears that either the echo or painting command is deleting my bookmark. Is there any way around this?

BTW, how are the Echo and me.painting commands/properties different? What does each do?

Thanks.

Wayne
 
This must be for a later version of Access. I get the following compile error:
"Method or data member not found."

Apologies, I'd just been working with an Excel query and this method is from Excel not Access.
 
BTW, how are the Echo and me.painting commands/properties different? What does each do?

Echo is for the complete database.
me.painting is for the current form (the form from where the code is started).

There should only be one method in your code, I would go for me.painting, as it is form based.
 

Users who are viewing this thread

Back
Top Bottom