PDA

View Full Version : how to write codes for update fields



daniel76
04-13-2008, 07:08 PM
Hi,

I have got a problem with implementing update fields in VBA in word document.

See that i have been using { DOCVARIABLE myvar } but the problem is it won't show the value of myvar unless i right-clicked on it and selected "update fields". It would then work. I have tried to implement printpreview in the code but to no avail.

with activedocument
.variables("myvar").value = TxtFirstName.Text
.printpreview
.closeprintpreview
endwith

Note: i typed in the codes, not copied directly from the VBA

Is there anyone know how to write codes to execute the update fields behind the scene? i tried to cheat by recording the macro but it didn't let me to carry out update fields. Hence, couldn't get the code.

BTW, this is for office word 03

Thank you in advance

daniel76
04-13-2008, 09:57 PM
Hi,

This issue has been fixed. Thank you for your time to read this post.

lucas
04-14-2008, 07:03 AM
Would you be kind enough to share your solution with the board please?

daniel76
04-14-2008, 05:48 PM
Hi Lucas,

Yes, of course. Sorry about that.

The following is the code i used to update field when it comes to using DOCVARIABLE

with activedocument
.variables("myvar").value = txtFirstName.Text
.fields.update
.printpreview
.closeprintpreview
end with

This solved my problem.