I've got a VC++ component that opens Word and creates a new document
based on a user specified document template. The DDE fields in the
document template are then merged with data from our database.

With one customer they use protected forms which won't allow the
updating of the document. To be able to do this I need to turn
protected fields off when the document is created (I've used AutoNew
which works), then turn protection back on after the document is
updated and displayed. However with out making a Hotfix to our software
I can't see a way in VBA (an event probably) to allow me to turn this
protection on after the update.

Any ideas gratefully received.

RE: Protected Forms and VBA events by zkid

zkid
Thu Oct 27 12:07:07 CDT 2005

A little confused here - is the whole form protected, or are only individual
fields protected?

Withiout knowing how the forms are set up, the way I see it, you have a
couple of options:

1. There is code available to unprotect a form and then re-protect it
without losing the data (which I think maybe is what you're looking for
here?).
2. You can change the merge fields in the protected form to formfields.
There is code to then update each of these formfields with each merge field,
but this would be time-consuming)

If you need #1, I think you will need to count the number of sections when
the merge is complete, and then plug in that number in the following code:

This code is directly from VBA help:

If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If

The NoReset is the most important here, as that is what controls whether or
not the data is wiped out when you protect the doc.

If you do need to protect it section-by-section, this code might be helpful:

Sub ProtectCurSection(iSecNum As Integer, iNumSections As Integer)

'Unprotect other stuff first - Word goes overboard

For i = 1 To iNumSections
ActiveDocument.Sections(i).ProtectedForForms = False
Next i

ActiveDocument.Sections(iSecNum).ProtectedForForms = True
ActiveDocument.Protect Password:="", NoReset:=True, Type:= _
wdAllowOnlyFormFields

End Sub

Hope this helps!

Greetings from California


"Daz" wrote:

> I've got a VC++ component that opens Word and creates a new document
> based on a user specified document template. The DDE fields in the
> document template are then merged with data from our database.
>
> With one customer they use protected forms which won't allow the
> updating of the document. To be able to do this I need to turn
> protected fields off when the document is created (I've used AutoNew
> which works), then turn protection back on after the document is
> updated and displayed. However with out making a Hotfix to our software
> I can't see a way in VBA (an event probably) to allow me to turn this
> protection on after the update.
>
> Any ideas gratefully received.
>
>

Re: Protected Forms and VBA events by Daz

Daz
Tue Nov 01 04:50:05 CST 2005

Thanks for your suggestions. Sadly I can't see how it'll resolve my
issue.

To answer your question first though, yes it is a protected form.

Suggestion 1. I know how to unprotect and reprotect my form using code
in the document template. The problem here is that my component
launches Word and creates a new existance of my template which fires
AutoNew where I unprotect my form. My component then goes through all
the DDE fields in the document and does a merge with our database.
After this is complete I need to protect the fields again. I can't see
any event I can use in VBA that is a post AutoNew i.e. I need something
that fires once the document is displayed.

Suggestion 2. I'm a bit lost with this one and can't see how it'll
resolve the problem.

Thanks for your input and any additionals (and California is a great
place as is Scotland :-) )


Re: Protected Forms and VBA events by Charles

Charles
Tue Nov 01 08:35:47 CST 2005

A completed mailmerge destroys protected form fields. They disappear as
fields. That is how it is.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"Daz" <darrenbichan@hotmail.com> wrote in message
news:1130842205.634151.308340@g43g2000cwa.googlegroups.com...
> Thanks for your suggestions. Sadly I can't see how it'll resolve my
> issue.
>
> To answer your question first though, yes it is a protected form.
>
> Suggestion 1. I know how to unprotect and reprotect my form using code
> in the document template. The problem here is that my component
> launches Word and creates a new existance of my template which fires
> AutoNew where I unprotect my form. My component then goes through all
> the DDE fields in the document and does a merge with our database.
> After this is complete I need to protect the fields again. I can't see
> any event I can use in VBA that is a post AutoNew i.e. I need something
> that fires once the document is displayed.
>
> Suggestion 2. I'm a bit lost with this one and can't see how it'll
> resolve the problem.
>
> Thanks for your input and any additionals (and California is a great
> place as is Scotland :-) )
>