Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-10-2021, 11:47 AM
brent chadwick brent chadwick is offline Protect form fields when updating Windows 8 Protect form fields when updating Office 2013
Advanced Beginner
Protect form fields when updating
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default Protect form fields when updating

Hey Guys, I've been using this macro for many years to protect form fields when updating them-until now. Suddenly in 365 this macro does not work. It does not select all the text in the doc, nor does it update the fields. Has there been a change in the VBA code language? Here's the macro-




Code:
Sub UpdateAllFields()
' UpdateAllFields Macro
 If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
If ActiveDocument.ProtectionType <> wdNoProtection Then
    ActiveDocument.Fields.Update
    ActiveDocument.Unprotect
   End If
End Sub
Thanks-
Reply With Quote
  #2  
Old 04-10-2021, 02:14 PM
macropod's Avatar
macropod macropod is offline Protect form fields when updating Windows 10 Protect form fields when updating Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Why are you protecting the document before updating the fields fields, then unprotecting it afterwards? That shouldn't be necessary and seems a strange way to go about things. Try:
Code:
Sub UpdateFields()
Application.ScreenUpdating = False
With ActiveDocument
  .Fields.Update
  .PrintPreview
  .ClosePrintPreview
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-11-2021, 01:12 PM
brent chadwick brent chadwick is offline Protect form fields when updating Windows 8 Protect form fields when updating Office 2013
Advanced Beginner
Protect form fields when updating
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

Seeing that I or someone wrote that macro some 8 of so years ago, why it was written that way would be pure speculation.
Questions-what does print preview do code wise and why use it? (curious, want to learn). Given that there are a lot of form fields in these forms, and the people using them are let's say less than computer genius material, should I write an exit macro to protect the individual fields after they are filled in?
Thanks Paul, you are the best-
Reply With Quote
  #4  
Old 04-11-2021, 02:46 PM
macropod's Avatar
macropod macropod is offline Protect form fields when updating Windows 10 Protect form fields when updating Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by brent chadwick View Post
what does print preview do code wise and why use it? (curious, want to learn)
Toggling Print Preview updates fields that are not updated via Fidlds.Update.
Quote:
Originally Posted by brent chadwick View Post
Given that there are a lot of form fields in these forms, and the people using them are let's say less than computer genius material, should I write an exit macro to protect the individual fields after they are filled in?
Ordinarily, one shouldn't need a macro to update fields in a document using formfields. All that should be needed is for the formfields upon which any updates are to be based should have their' Calculate on Exit' property checked.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to protect cells and still be able to use all data entry form Jae Excel 2 11-13-2019 05:32 PM
Protect form fields when updating Auto-Updating Text Fields in Form Fill doc strodden Word 2 08-28-2017 07:01 AM
Macro to keep formatted form fields after mail merge or replace text with formatted form fields jer85 Word VBA 2 04-05-2015 10:00 PM
Protect form fields when updating Updating field codes without clearing form fields wwwKris Word 1 08-29-2014 07:03 AM
Protect certain parts of a form --emma-- Word 0 07-20-2010 12:27 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:00 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft