Bonjour,
Dans son message, < (e-mail address removed) > écrivait :
| The code that is causing the problem is simply:
|
| .Fields.Update
|
| When I disable this, the ref fields I want updated of
| course are not updated, but the formfields remain as they
| should. If I enable this and run userform, all the
| fields are empty. I can, since this is the last action
| performed to the document, undo that action and see that
| updating the fields is in fact what cleared them.
|
I guess I still do not understand your situation or there is something else
interfering in your code.It is probably because I do not see the connection
between the userform and the formfields. You have a userform the asks the
users to fill out some info, and then you populate the formfields with that
info. Is your userform doing anything else? If not, the userform is
superfluous. Just let the user navigate in the document filling out the
formfields.
There is a simple way of updating REF fields based on formfields. Make sure
you check the "Calculate on exit" checkbox in the formfield property dialog
box. Then leaving the formfields will automatically update the REF fields.
But for this to work you must be in a document protected for forms (Tools >
Protect)
If you have Formfields and REF fields pointing to those formfields, then
ActiveDocument.Fields.Update
will update all REF fields and will not change the content of the
formfields.
The only way I can reproduce your situation is by unprotecting the document.
Is this what you are doing?
In that case, you do not need formfields (In fact you cannot use them if the
document is unprotected). See the following code for a sample of what you
could do instead. You just need a userform with a textbox and a command
button, a bookmark in the document named Text1 and some REF fields pointing
to that bookmark.
'_______________________________________
Private Sub CommandButton1_Click()
FillBookMarks "Text1", Me.TextBox1.Text
ActiveDocument.Fields.Update
Me.Hide
Unload Me
End Sub
'_______________________________________
'_______________________________________
Function FillBookMarks(BKName As String, BKContent As String)
Dim MyRange As Range
With ActiveDocument
Set MyRange = .Bookmarks(BKName).Range
MyRange.Text = BKContent
.Bookmarks.Add BKName, MyRange
End With
End Function
'_______________________________________
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org