Oddity with Field Update in a protected form Table

G

Greg Maxey

To see this issue create a single row two column table and insert text
formfield in the first cell and and a REF to that formfield in the second
cell. Protect the document and add some text to the formfield.

Run this code:

Sub DumbfoundedI()
Dim oTbl As Table
Set oTbl = ActiveDocument.Tables(1)
MsgBox oTbl.Range.Fields.Count
MsgBox ActiveDocument.Fields.Count
oTbl.Range.Fields.Update

The message box proves that there are two fields in the table and in the
activedocument yet the REF field doesn't update. Does anyone know why?

However, if I run either of the following procedures the REF field does
update:

Sub DumbfoundedII()
ActiveDocument.Fields.Update
End Sub

or

Sub DumbfoundedII()
Dim oTbl As Table
Dim oFld As Field
Set oTbl = ActiveDocument.Tables(1)
For Each oFld In oTbl.Range.Fields
oFld.Update
Next oFld
End Sub

or:

Sub DumbfoundedIV()
Dim oTbl As Table
Dim oRng As Range
Set oTbl = ActiveDocument.Tables(1)
Set oRng = oTbl.Range
oRng.Start = oRng.Start + 1
oRng.End = oRng.End + 1
oRng.Fields.Update
End Sub
 
G

Greg Maxey

David,

While I wasn't aware of that KB article, I was aware that I didn't see the
behaviour if I used "Calculate on exit." I my real problem is with a bigger
form that I am working on. In that form, I am creating new rows in a
protected form that contains text and calculation formfields.

I don't know why, but calculate on exit fails (I think because my on exit
macro takes over) and the fields aren't updated. I can send you a copy of
the file if you want to have a peek.

You can reach me through the "Contact Me" link on my website.

Thanks.
 
D

David Sisson

I don't know why, but calculate on exit fails (I think because my on exit
macro takes over) and the fields aren't updated.  I can send you a copy of
the file if you want to have a peek.
Interesting...

I've requested that file via the web site.

David
 

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