How do I get out of my protected Section?

B

Brendan

I am using the code of "ActiveDocument.Sections(1).ProtectedForForms = True"
to protect page 1 which works fine. On the last form field I call a macro on
exit to go to a bookmark on page 2. This macro was tested and works fine as
long as the document is not protected. However, once the above code is run
on the AutoNew, and once I exit the field to go to the bookmark, my cursor
simply goes to the first field on Page 1 and not to the bookmark on page to.

Is there a line of code I need to insert in the my macGoToNarr bookmar that
allows me to go to page 2 from the protected section in page 1?
 
J

Jonathan West

Brendan said:
I am using the code of "ActiveDocument.Sections(1).ProtectedForForms =
True"
to protect page 1 which works fine. On the last form field I call a macro
on
exit to go to a bookmark on page 2. This macro was tested and works fine
as
long as the document is not protected. However, once the above code is
run
on the AutoNew, and once I exit the field to go to the bookmark, my cursor
simply goes to the first field on Page 1 and not to the bookmark on page
to.

Is there a line of code I need to insert in the my macGoToNarr bookmar
that
allows me to go to page 2 from the protected section in page 1?

Is there a section break between pages 1 and 2?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
B

Brendan

Yes. Section break is outside the table at the bottom of page1. There is
only one in the template.
 
B

Brendan

I can do it with the following code:

ActiveDocument.Sections(1).ProtectedForForms = False
ActiveDocument.Unprotect

but that unprotects the whole document.

So I need to reprotect Section 1 after the user gets to the narrative on
page 2. Basically, anytime the user is on page 1, section 1 needs to be
protected.
 
J

Jean-Guy Marcil

Brendan was telling us:
Brendan nous racontait que :
I can do it with the following code:

ActiveDocument.Sections(1).ProtectedForForms = False

Unless the sections that need protecting are change dynamically, you do not
need this line in your code.

Just manually assign which section needs protection when you create the
template, then only use

ActiveDocument.Unprotect

to protect/unprotect the whole document. Only the sections labelled as "To
be protected" will be affected.
but that unprotects the whole document.

So I need to reprotect Section 1 after the user gets to the narrative
on page 2. Basically, anytime the user is on page 1, section 1
needs to be protected.

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

Jean-Guy Marcil

Brendan was telling us:
Brendan nous racontait que :
I am using the code of "ActiveDocument.Sections(1).ProtectedForForms
= True" to protect page 1 which works fine. On the last form field I
call a macro on exit to go to a bookmark on page 2. This macro was
tested and works fine as long as the document is not protected.

Show us your code.
However, once the above code is run on the AutoNew, and once I exit
the field to go to the bookmark, my cursor simply goes to the first
field on Page 1 and not to the bookmark on page to.

Is there a line of code I need to insert in the my macGoToNarr
bookmar that allows me to go to page 2 from the protected section in
page 1?



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

Brendan

Here is the code. It will take me to the bookmark on Page 2 but if the user
needs to go back to page 1 and make some changes to the form fields, then the
document is left unlocked. I could always put a macro button on the toolbar
that locks and unlocks the document but I am trying to make this as autmated
as possible to where no matter what, Page 1, with a section brake at the
bottom, is always protected and that if the user clicks in the table on page
2 (or anywhere other than page 1) for the narrative, the document he/she is
allowed to start typing.

Sub macGoToBMPropNarr()

' Checks to see if document is unprotected already

If ActiveDocument.Sections(1).ProtectedForForms = True Then
ActiveDocument.Sections(1).ProtectedForForms = False
ActiveDocument.Unprotect
End If

If ActiveDocument.Bookmarks.Exists("swPropNarr") Then
ActiveDocument.Bookmarks("swPropNarr").Select
End If

End Sub
 
J

Jean-Guy Marcil

Brendan was telling us:
Brendan nous racontait que :
Here is the code. It will take me to the bookmark on Page 2 but if
the user needs to go back to page 1 and make some changes to the form
fields, then the document is left unlocked. I could always put a
macro button on the toolbar that locks and unlocks the document but I
am trying to make this as autmated as possible to where no matter
what, Page 1, with a section brake at the bottom, is always protected
and that if the user clicks in the table on page 2 (or anywhere other
than page 1) for the narrative, the document he/she is allowed to
start typing.

Sub macGoToBMPropNarr()

' Checks to see if document is unprotected already

If ActiveDocument.Sections(1).ProtectedForForms = True Then
ActiveDocument.Sections(1).ProtectedForForms = False
ActiveDocument.Unprotect
End If

If ActiveDocument.Bookmarks.Exists("swPropNarr") Then
ActiveDocument.Bookmarks("swPropNarr").Select
End If

End Sub

As I wrote in my other reply in this thread, if you set up your template
properly, all you need is
ActiveDocument.Unprotect

Now, in your code, you are unprotecting the document.
May I ask why?
Also, you are not re-protecting it, so of course, section 1 is now
unprotected.

I have the feeling that all you want to do is send the user to the beginning
of the editable part of the document when they are done typing in the
formfields. If this is the case, then you do not need a macro.
Just protect section 1 (and not section 2) and then the cursor will
automatically go to the beginning of section 2 when they tab out of the last
field in section 1.

Now, if you really need a macro, try this:

Sub macGoToBMPropNarr()
Application.OnTime When:=Now, Name:="ReallymacGoToBMPropNarr"
End Sub

Sub ReallymacGoToBMPropNarr()
If ActiveDocument.Bookmarks.Exists("swPropNarr") Then
ActiveDocument.Bookmarks("swPropNarr").Select
End If
End Sub

It seems that without the macro to call another macro, Word will not
properly get to the bookmark.

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

Brendan

That worked perfectly. Thank you very much. I can now leave the document
protected with Section(2) unprotected. I don't know why Word did not like
simply executing the "ReallymacGoToBMPropNarr()" on its own.

Brendan
 

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