Document scrolls after exiting DocumentBeforeSave

G

Gordon

I have created a form template that uses application
events to that check that certain fields are not blank
before the document can be saved. (My thanks to Peter
Hewett and Jezebel from previous posts).

One interesting side-effect of this event catcher is that
each time the document is saved (with or without the
required field filled in), the document scrolls to the top
of the first page. The cursor does not move, just the
document. This happens on both "normal" save (cntrl-S)
and auto saves. It also happends regardless of whether or
not the form is protected.

What can I do to stop this scrolling?

My code is listed below.

Thanks,
Gordon.

''''''''''''''''''''''''''''''
Option Explicit

' Application event logic taken from
'
http://word.mvps.org/FAQs/Customization/ProtectWord2000Plus
HeaderContent.htm

'reserve memory for an application variable
Private WithEvents wdApp As Word.Application

Private Sub Document_New()
'assign Word to the application variable
If wdApp Is Nothing Then
Set wdApp = ThisDocument.Application
End If
End Sub

Private Sub Document_Open()
'assign Word to the application variable
If wdApp Is Nothing Then
Set wdApp = ThisDocument.Application
End If
End Sub

Private Sub wdApp_DocumentBeforeSave(ByVal Doc As
Document, SaveAsUI As Boolean, Cancel As Boolean)

'quit if active doc isn't attached to this template
If Doc.AttachedTemplate <> ThisDocument Then Exit Sub

' Cancel save if Text1 is blank
If Doc.FormFields("Text1").Result = "" _
Then
MsgBox "Please enter Text1 before saving."
Doc.FormFields("Text1").Range.Select
Cancel = True 'Cancel the save
End If

End Sub
 
G

Gordon

I think I've narrowed down the scope of the problem. I
discovered that if my procedure does nothing but a simple
message box (see below), then the document doesn't
scroll. But if I put the "if" statement back in then it
does scroll.

Any clues what causes this?

Gordon

Private Sub wdApp_DocumentBeforeSave(ByVal Doc As
Document, SaveAsUI As Boolean, Cancel As Boolean)

'quit if active doc isn't attached to this template
If Doc.AttachedTemplate <> ThisDocument Then Exit Sub

' This statement does not make the document scroll
MsgBox ("This is DocumentBeforeSave")
End If

End Sub
 

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