Patrick C. Simonds was telling us:
Patrick C. Simonds nous racontait que :
This a sample of the code I am using, where "Text Box 217" represents
a TextBox I drew on the document and "TextBox1" is the TextBox on the
UserForm. This document is used by a small group (2 to 3 people) to
conduct an eligibility interview over the phone. They wanted the
ability to do the interview sections randomly based on the
conversation with the applicant. I created UserForms for the various
sections and on each UserForm there are buttons which allow them to
go to different parts of the interview. As the exit (terminate) each
UserForm the data is placed on the form. If the return to any
particular section to add or update data they can select the button
for that section, and when the UserForm opens it is populated with
the data currently on the form. It all works great here, but as I
mentioned before, when I took it to work, Word renumbered the
TextBoxes on the document (not the UserForms).
Private Sub UserForm_Terminate()
'Text Input''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Last Name
ActiveDocument.Shapes("Text Box 217").TextFrame.TextRange.Text =
TextBox1.Text
'First Name
ActiveDocument.Shapes("Text Box 218").TextFrame.TextRange.Text =
TextBox2.Text
If you want to stick to your textbox approach, you can name those textboxes.
Insert a textbox any way you want to, then select it and run the following
code:
Selection.ShapeRange(1).Name = "MyTextboxName"
and then use "MyTextboxName" elsewhere in your code.
If the user can be trusted not to upset the document layout, or if it is
protected for forms, you can use DOCVARIABLE fields instead of textboxes.
Create the document variables like this:
ActiveDocument.Variables("FirstDocVar").Value = TextBox1.Text
and in the document, place a field:
{DOCVARIABLE FirstDocVar}
This way you do not have to interact directly with the document other than
doing a
ActiveDocument.Fields.Update
And loading the values is also easy:
TextBox1.Text = ActiveDocument.Variables("FirstDocVar").Value
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org