update footer when protected document

A

Alexis

Hello guys
I have a document, template with forms, and I want to be able to update my
footer by entering information in my userform.

I can only make the update when my form is protected when I use the Field
FILL-IN, but with the field REF I can't.
with the FILL-IN field when i start a new document pops-up a window asking
me for this fields, and only after my userform.
But I want to be able to do that with my user form.

'This is the code that I have in my userform
Private Sub fillinbuttom_Click()

'no tanks Loaded
ntanks = UserForm1.notanks.Text
ActiveDocument.FormFields("ntanks").Result = ntanks
'input salg No

salg = UserForm1.salgno.Text
ActiveDocument.Bookmarks("salg").Range.Text = salgno
'input revison No

rev = UserForm1.revno.Text
ActiveDocument.Bookmarks("rev").Range.Text = revno


Unload Me

End Sub

'This is the code That I wrote for my module

Sub Formsfooterupdate()

' If document is protected, Unprotect it.
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=""
End If


If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Fields.Update
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

' ReProtect the document.
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
End If

End Sub

But still I have the same problem and an error popup in
salg=userfor1.salgno.text

I think I am doing a mistake.

Could someone help me with this.
 
D

Doug Robbins - Word MVP

Do you really need the document to be protected?

If you are getting an error with the salgno.Text line, then probably you do
not have a control by that name on the form.

If you want to update a field in the footer of the document, use the
following code, which should not require that the document be unprotected

Selection.Sections(1).Footers(wdHeaderFooterPrimary).Range.Fields.Update

That will update a Ref field in the footer that refers to the text of a
bookmark (formfield) in the body of the document. That code could be
located with the code that is transferring the data from the userform into
the document so that you would not need to run a separate macro to update
the footer.

I used Selection above because you were accessing the current page footer.
You could run into a problem if there is more than one Section in the
document, because you may not have the selection on the page that is in the
Section whose footer you want updated.

Tell us a bit more about the structure of your document and we can probably
suggest how best to go about this.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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