Updating fields using screen update doesn't work with command butt

  • Thread starter Thread starter Kamran
  • Start date Start date
K

Kamran

Hello,
The code below works perfectly when tabbing away from a form entry field
that runs the macro on exit, but breaks on the second line when activated in
a Private Sub from a command button -- why?

Application.ScreenUpdating = False
ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview
Application.ScreenUpdating = True
 
Hi, Cindy. Thanks for the remind on providing more info, will do (this is on
Word 2003). I think you're right about the focus on the button. I had the
code above in the sub for a command button click so that it would update a
formula SUM field, but it wouldn't work. Instead I came up with the idea to
assign a "Score" bookmark to the field and just update it directly. Hope
that makes sense.

Private Sub CommandButton1_Click()
ActiveDocument.Variables("var1").Value = 2
ActiveDocument.Bookmarks("Score").Range.Fields.Update
End Sub
 
Back
Top