Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

I have a big problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick C. Simonds - 17 Apr 2007 01:19 GMT
Well enough about me.

I have a multi-page form that I have created in Word, which is filled in
using VBA. As such this document has over 80 TextBoxes in it which are
populated by VBA code. Everything works great at home, but when I took the
document to work and opened it Word renumbered all of the TextBoxes in the
document. That is quite a problem since I have so many VBA references to the
TextBoxes.

Is there any way to ensure that the TextBox numbers will not get reassigned
when the document is opened on a different machine?
Jean-Guy Marcil - 17 Apr 2007 13:51 GMT
Patrick C. Simonds was telling us:
Patrick C. Simonds nous racontait que :

> Well enough about me.
>
[quoted text clipped - 7 lines]
> Is there any way to ensure that the TextBox numbers will not get
> reassigned when the document is opened on a different machine?

What Word version?

In some cases, if you actually give them names of your own, chances are that
the names will not be changed, but there is no guarantee as I have heard of
people who had assigned their own names and Word still changed the names...

ActiveX controls are flaky in the Word environment.
I would advise not using them.

What is the context for the document usage? Who uses it and to what purpose?
Is it protected for forms?

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Patrick C. Simonds - 17 Apr 2007 15:21 GMT
Version 2003. These are TextBoxes on the document it's self (I use VBA to
place text in the box). I know you can rename a TextBox that is used on
UserForm, but I am unaware how you would rename a TextBox you drew on a
document.

> Patrick C. Simonds was telling us:
> Patrick C. Simonds nous racontait que :
[quoted text clipped - 23 lines]
> What is the context for the document usage? Who uses it and to what
> purpose? Is it protected for forms?
Jean-Guy Marcil - 17 Apr 2007 16:07 GMT
Patrick C. Simonds was telling us:
Patrick C. Simonds nous racontait que :

> Version 2003. These are TextBoxes on the document it's self (I use
> VBA to place text in the box). I know you can rename a TextBox that
> is used on UserForm, but I am unaware how you would rename a TextBox
> you drew on a document.

Right click on it and select "Properties"

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Patrick C. Simonds - 17 Apr 2007 16:31 GMT
When I do that, Properties is not an option. Reading between the lines of
all this great help I have been receiving, I think I have been creating my
TextBoxes the wrong way. I have been using   Insert then TextBox and then
drawing my TextBox. I think what I should be doing is creating them by
selecting the Developer bar.

> Patrick C. Simonds was telling us:
> Patrick C. Simonds nous racontait que :
[quoted text clipped - 5 lines]
>
> Right click on it and select "Properties"
Jean-Guy Marcil - 17 Apr 2007 16:54 GMT
Patrick C. Simonds was telling us:
Patrick C. Simonds nous racontait que :

> When I do that, Properties is not an option. Reading between the
> lines of all this great help I have been receiving, I think I have
> been creating my TextBoxes the wrong way. I have been using   Insert
> then TextBox and then drawing my TextBox. I think what I should be
> doing is creating them by selecting the Developer bar.

What Word version?

Because you wrote about numbered textboxes, I thought you were writing about
ActiveX controls that are inserted with the "Controls Toolbox" toolbar.

Now, finally, I understand what you are doing.

How were the textboxes numbered (I.e, how did you know which textbox was
represented by which number?) Are you referring the index number in the
shape collection?
Can I see the some of the code you used to fill the textboxes?

And again, in case there is an easier way to achieve your goal, what is the
context for the document usage? Who uses it and to what purpose?
Is it protected for forms?

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Patrick C. Simonds - 17 Apr 2007 17:11 GMT
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

> Patrick C. Simonds was telling us:
> Patrick C. Simonds nous racontait que :
[quoted text clipped - 21 lines]
> the context for the document usage? Who uses it and to what purpose?
> Is it protected for forms?
Jean-Guy Marcil - 17 Apr 2007 18:09 GMT
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
[quoted text clipped - 23 lines]
> 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

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.