Insert to OVERWRITE not ADD to field??

A

Angyl

K. I have a Word2003 Template with bookmarked Form Fields.
By sample, one of the fields is named "ClientName"

There is a Userform (Named UserForm1) to go with this Form Template.

A Macro when you open the template for the first time, opens UserForm1.

UserForm1 contains all the same fields as the Template. When you press the
Command Button on the UserForm1 This code executes:

With ActiveDocument
.FormFields("ClientName").Result = ClientName

End With
ActiveDocument.Fields.Update
UserForm1.Hide
-----

Perfect, the UserForm puts the inputted data into the form and goes away.

NOW here's the problem.

If you save what you've done, and open it again, I've put in a Macro to open
the UserForm Again and repopulate the data from the Template into the
UserForm so you can make changes.

Sub autoopen()
'
' autoopen Macro
' Macro created 5/4/2006 by Timothy Allen
'
With UserForm1

UserForm1.ClientName.Text =
ActiveDocument.Bookmarks("ClientName").Range.Text

Great.

THE PROBLEM IS...that when you are done making changes and hit that command
button again to go back to the template EVERYTHING goes to Hell in the
document. I think it is re-inserting the data AGAIN, (rather than
overwriting it). The formulas get all messed up, calculating things, spaces
and weird numbers are inserted...

Any suggestions for fixing that?
 
G

Greg Maxey

I don't know why you are using formfields in one part of your code and
bookmarks in the other?

A simple test with two formfields in the document, a userform with two
textboxes and a command button works using this code:

Private Sub CommandButton1_Click()
ActiveDocument.FormFields("Text1").Result = Me.TextBox1.Text
ActiveDocument.FormFields("Text2").Result = Me.TextBox2.Text
Me.Hide
End Sub
Private Sub UserForm_Initialize()
Me.TextBox1.Text = ActiveDocument.FormFields("Text1").Result
Me.TextBox2.Text = ActiveDocument.FormFields("Text2").Result
End Sub
 
D

Doug Robbins - Word MVP

As your Command button code is setting the .Result of the formfields,
assuming that this same code is being used the second time, the .Result
should be updated to the new data (that is replaced), that would be unless
in the userform, the "new" information is being added to the end of the text
in the control, possibly because that text as scrolled out of view.

Instead of using formfields in the template, I would use docvariable fields
and have the code in the userform create and set the values of the variables
to the data entered into the userform and then update the fields in the
document so that the information entered into the form is displayed in the
docvariable fields. On reloading the userform, you can populate the
controls on it by accessing the values of the respective variables.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Greg Maxey

Doug,

I abandon this OP. Seems he is frustraded by a demanding boss. He wants
answers but is unwillling to acknowledge assistance. He keeps posting until
he gets resolution and then nothting.
 
A

Angyl

Wow...that's an interesting way of looking at it. I'll give that a shot,
Doug. Thanks!
 

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