trouble with a form with protected sections

K

Keith G Hicks

I have a document (word 2003) with 3 sections. The first and 3rd sections
are protected as a form. The 2nd is not protected. There are form fields in
the first section that are populated with data from code from an MS Access
app. There are also form fields that are not set up with data from the
database. These are manually filled in by a user after the document is
created. The 2nd section (the one that is not protected) has a single
bookmark in it that is also to be populated via code. This bookmark is not a
form field because a person's initials get posted to it and then autotext
turns that into a signature. The form fields in section 1 are filling in
just fine. The 3rd section just has text in it that needs to remain
unchanged when the user edits the form fields in the resultant document.
The trouble is that when the code tries to insert the initials into the
bookmark in section 2 I get an error saying the document is protected.
Here's the code. Can anyone tell me what's wrong? I think I'm not actually
getting to section 2. But not sure.

Set docWord = objWord.Documents.Add(Template:=sWordFormsPath &
"MyTemplate.dot")

With docWord.FormFields
.Item("WholeName").Result = sCWName
.Item("SSN").Result = sCSSN
.Item("CustomerName").Result = sCCustName
.Item("DOB").Result = sCDOB
.Item("ClientAge").Result = sCAge
End With

If Not fncIsBlank(sCCust) Then
If MsgBox("Include Signature?", vbYesNo, "Signature Verify") = vbYes
Then
Set rngWord = docWord.GoTo(what:=wdGoToSection,
which:=wdGoToAbsolute, Count:=2)
Set rngWord = docWord.GoTo(what:=wdGoToBookmark,
Name:="CustSignature")
rngWord.InsertAfter sCCust
On Error Resume Next 'only necessary if autotext is not set for
this customer in the normal.dot template
rngWord.InsertAutoText
On Error GoTo fncMakeDocument_ERR
End If
End If

Thanks,

Keith
 
C

Cindy M -WordMVP-

Hi Keith,

Why not set a break point in your code so that you can see where the insertion
point actually is?

FWIW, you certainly don't need to first go to the section. For that matter,
you shouldn't even need to GoTo the bookmark:

objRefToTemplateWithAutoText.AutoTextEntries("NameOfEntry").Insert _
Where:=docWord.Bookmarks("TheName").Range, RichText:=True

Note: I've just tested, and this does work in an unprotected section of a
protected document.
I have a document (word 2003) with 3 sections. The first and 3rd sections
are protected as a form. The 2nd is not protected. There are form fields in
the first section that are populated with data from code from an MS Access
app. There are also form fields that are not set up with data from the
database. These are manually filled in by a user after the document is
created. The 2nd section (the one that is not protected) has a single
bookmark in it that is also to be populated via code. This bookmark is not a
form field because a person's initials get posted to it and then autotext
turns that into a signature. The form fields in section 1 are filling in
just fine. The 3rd section just has text in it that needs to remain
unchanged when the user edits the form fields in the resultant document.
The trouble is that when the code tries to insert the initials into the
bookmark in section 2 I get an error saying the document is protected.
Here's the code. Can anyone tell me what's wrong? I think I'm not actually
getting to section 2. But not sure.

Set docWord = objWord.Documents.Add(Template:=sWordFormsPath &
"MyTemplate.dot")

With docWord.FormFields
.Item("WholeName").Result = sCWName
.Item("SSN").Result = sCSSN
.Item("CustomerName").Result = sCCustName
.Item("DOB").Result = sCDOB
.Item("ClientAge").Result = sCAge
End With

If Not fncIsBlank(sCCust) Then
If MsgBox("Include Signature?", vbYesNo, "Signature Verify") = vbYes
Then
Set rngWord = docWord.GoTo(what:=wdGoToSection,
which:=wdGoToAbsolute, Count:=2)
Set rngWord = docWord.GoTo(what:=wdGoToBookmark,
Name:="CustSignature")
rngWord.InsertAfter sCCust
On Error Resume Next 'only necessary if autotext is not set for
this customer in the normal.dot template
rngWord.InsertAutoText
On Error GoTo fncMakeDocument_ERR
End If
End If

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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