Freeze a field result so users can't change it?

M

mccaskey

Is there a way to programmatically freeze a field result so that
users' can't change it? The locked property stops Word from updating
the field, but the user can still manually change the field result.
 
B

Bear

Mccaskey:

All I can think of is to trap the save command (maybe the print command too)
and force a field update. That way they could change the result but they
could never save their changes or print them.

Bear
 
J

Jean-Guy Marcil

mccaskey was telling us:
mccaskey nous racontait que :
Is there a way to programmatically freeze a field result so that
users' can't change it? The locked property stops Word from updating
the field, but the user can still manually change the field result.

If everyone involved with the document is using Word 2003 and above, you can
lock part of the document. In fact, you do the opposite, you make some
ranges of the document available to everyone.

Select the text up to the beginning of the field, then
Tools
Protect Document
in the Protect Document Task Pane, in the middle:
Click on ALlow only thjis tytpe of editing
and select No Changes (Read Only)
check the "Everyone" checkbox
Select the text starting just after the field up to the end of the document
and repeat as above
check the "Everyone" checkbox
When you are done , click on "Yes, Start Enforcing Protection" and add a
password if you want to.

If you are dealing with Word version before 2003, you will need to use the
regular Form Protection and sections. But this will block some tools.

If this is what you want, write back and we will point you toward the code
for doing this programatically.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
M

mccaskey

mccaskey was telling us:
mccaskey nous racontait que :


If everyone involved with the document is using Word 2003 and above, you can
lock part of the document. In fact, you do the opposite, you make some
ranges of the document available to everyone.

Select the text up to the beginning of the field, then
Tools
Protect Document
in the Protect Document Task Pane, in the middle:
Click on ALlow only thjis tytpe of editing
and select No Changes (Read Only)
check the "Everyone" checkbox
Select the text starting just after the field up to the end of the document
and repeat as above
check the "Everyone" checkbox
When you are done , click on "Yes, Start Enforcing Protection" and add a
password if you want to.

If you are dealing with Word version before 2003, you will need to use the
regular Form Protection and sections. But this will block some tools.

If this is what you want, write back and we will point you toward the code
for doing this programatically.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:http://www.word.mvps.org

This does look like it might work. I would indeed appreciate any
advice on how to do it programmatically. In the Word VB Reference, I
see the Protect method and the Protected and Protect properties, but
they aren't enlightening me.

My situation is as follows. I provide an icon that lets a user insert
an ADDIN field whose code.text my code controls. Under various
conditions, my code queries a database and sets the results of all
such fields. I don't want the user messing with the fields' results.

There will be many of these fields. They will not all be inserted at
once. They may be placed in the main text, in footnotes, and in
endnotes.

Any advice appreciated.

John
 
J

Jean-Guy Marcil

mccaskey was telling us:
mccaskey nous racontait que :
This does look like it might work. I would indeed appreciate any
advice on how to do it programmatically. In the Word VB Reference, I
see the Protect method and the Protected and Protect properties, but
they aren't enlightening me.

My situation is as follows. I provide an icon that lets a user insert
an ADDIN field whose code.text my code controls. Under various
conditions, my code queries a database and sets the results of all
such fields. I don't want the user messing with the fields' results.

There will be many of these fields. They will not all be inserted at
once. They may be placed in the main text, in footnotes, and in
endnotes.

Any advice appreciated.

John

Here is some code top show you what can be done in Word 2003 and above.
This example makes only the first paragraph in the document editable:


Dim rgeAllow As Range

Set rgeAllow = ActiveDocument.Range.Paragraphs(1).Range

rgeAllow.Editors.Add wdEditorEveryone

ActiveDocument.Protect wdAllowOnlyReading, True, "mypassowrd"



Now, since your fields are going to be scattered everywhere in the
document.... it is going to be very difficult.
Unless... if this process takes place upon crating a document, and if the
fields are all in known places, then you can manually make those editable in
the template itself. In that case, no code necessary.
If this scenario in snot possible, your real challenge will be to pick all
the areas outside the fields... Maybe you could bookmark the area in between
the fields...
Maybe a clever Find to select the area between two fields...

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
M

mccaskey

mccaskey was telling us:
mccaskey nous racontait que :









Here is some code top show you what can be done in Word 2003 and above.
This example makes only the first paragraph in the document editable:

Dim rgeAllow As Range

Set rgeAllow = ActiveDocument.Range.Paragraphs(1).Range

rgeAllow.Editors.Add wdEditorEveryone

ActiveDocument.Protect wdAllowOnlyReading, True, "mypassowrd"

Now, since your fields are going to be scattered everywhere in the
document.... it is going to be very difficult.
Unless... if this process takes place upon crating a document, and if the
fields are all in known places, then you can manually make those editable in
the template itself. In that case, no code necessary.
If this scenario in snot possible, your real challenge will be to pick all
the areas outside the fields... Maybe you could bookmark the area in between
the fields...
Maybe a clever Find to select the area between two fields...

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:http://www.word.mvps.org

Thanks! I now see that .Editors is the key piece.

Here is what I'm now trying: First protect the document and give
everyone editing access to everything in the document. (I hadn't found
wdEditorsEveryone. Thanks!) Then right after I add my field, do this:

myNewField.Select
ActiveDocument.Unprotect
Selection.Editors(wdEditorsEveryone).Delete
ActiveDocument.Protect (wdAllowOnlyReading)

I don't have it all worked out, but .Editors.Delete seems to be the
key.

I also don't yet know how to do the first step, i.e., give everyone
access to the whole document, including to story ranges that do not
yet exist, but I'm still experimenting.

Thanks again,
John
 
M

mccaskey

Thanks! I now see that .Editors is the key piece.

Here is what I'm now trying: First protect the document and give
everyone editing access to everything in the document. (I hadn't found
wdEditorsEveryone. Thanks!) Then right after I add my field, do this:

myNewField.Select
ActiveDocument.Unprotect
Selection.Editors(wdEditorsEveryone).Delete
ActiveDocument.Protect (wdAllowOnlyReading)

I don't have it all worked out, but .Editors.Delete seems to be the
key.

I also don't yet know how to do the first step, i.e., give everyone
access to the whole document, including to story ranges that do not
yet exist, but I'm still experimenting.

Thanks again,
John

New problem: It appears that footnotes/endnotes can be protected only
all-or-nothing. I can't protect part of a footnote (such as the field
I'm inserting) and leave the rest open for editing.

Moreover, I can't even figure out how to protect the whole footnote
without also protecting the character before it in the main body.

Is that right?
 
J

Jean-Guy Marcil

mccaskey was telling us:
mccaskey nous racontait que :
New problem: It appears that footnotes/endnotes can be protected only
all-or-nothing. I can't protect part of a footnote (such as the field
I'm inserting) and leave the rest open for editing.

Moreover, I can't even figure out how to protect the whole footnote
without also protecting the character before it in the main body.

Is that right?

True on all counts!

Keep in mind that what you are trying to do is not what the protection was
intended for...

Normally, for what you are doing, you would have a form protected with
formfields where the user can type some text and your database fields would
automatically be protected.

I understand this is not what you want, so you are trying an in-between
solution... which gives in-between results!

Sorry I cannot help more... maybe someone else will have an "out-of-the-box"
idea...

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
M

mccaskey

mccaskey was telling us:
mccaskey nous racontait que :







True on all counts!

Keep in mind that what you are trying to do is not what the protection was
intended for...

Normally, for what you are doing, you would have a form protected with
formfields where the user can type some text and your database fields would
automatically be protected.

I understand this is not what you want, so you are trying an in-between
solution... which gives in-between results!

Sorry I cannot help more... maybe someone else will have an "out-of-the-box"
idea...

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:http://www.word.mvps.org

It's too bad. If protection worked in notes as it does everywhere
else, I'd be all set and this would all be easy. Grrr.

Or if locking field results really froze them. Grrr.

I'm out of ideas.
 

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