Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Tue, 12 Aug 2008 01:07:01 -0700,    group: microsoft.public.word.vba.general        back       


update footer when protected document   
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.
date: Tue, 12 Aug 2008 01:07:01 -0700   author:   Alexis

Re: update footer when protected document   
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

"Alexis"  wrote in message 
news:85DBB69A-823B-48EB-B68B-81720217BCF6@microsoft.com...
>
> 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.
date: Tue, 12 Aug 2008 18:43:50 +1000   author:   Doug Robbins - Word MVP

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us