Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word TextBox Syntax 2

Status
Not open for further replies.

SteveMersereau

Technical User
Feb 6, 2002
23
0
0
GB
I'd like to refer to a number of textboxes from within a module (There may be 20 or 30 so I can't pass as parameters).

Any ideas as to syntax?

Thanks!

Steve
"In the Jungle of the Senses
 
Hi Steve,

Could you please clarify?

1. What KIND of textboxes? Are they in the document? FormField textboxes? ActiveX textboxes? The syntax would be different.

2. Refer to how? To get something from the textbox? To get something out?

3. What exactly are you wanting to do? I don't understand your reference to not passing parameters.

Gerry
See my Paintings and Sculpture
 
Thanks for your lightning-fast response. Apologies for not being clear!

1 FormField Textboxes

2 To get text entered into the boxes after a button press

3 The idea is to for a Word doc to consist of a series of text boxes, similar to a questionaire. The end user will take this document and complete the text boxes with information from a survey. At the end s/he will press a 'complete' button and VBA will generate a new Word document using the information entered. What I don't want to do is this...

Call WriteSub(TextBox1.text As String, Textbox2.text As String, ... TextBox29 As String)

Best,

Steve Mersereau
"Tinkerbell, and Jack the Ripper
 
Hi Steve,

OK. The value of a FormField is:

ActiveDocument.FormFields("formfield_name").Result

So, depending on what you may want to do with format; AND if you want to add other text; AND if there are other formfields to deal with.....

This assumes, NO other formfields, you are NOT using proper styles (which you should...but most people do not), and you just want the results of ALL the formfields - separated by an extra paragraph ( re: not using styles). Oh, and it is using an ActiveX commandbutton in the document. You do not state how you are doing the "complete" button.

Code:
Sub CommandButton1_Click()
Dim myFF As FormField
Dim FFResult As String
Dim ThisDoc As Document
Dim ThatDoc As Document
Set ThisDoc = ActiveDocument
Application.Documents.Add
Set ThatDoc = ActiveDocument

ThisDoc.Activate
For Each myFF In ThisDoc.FormFields
    FFResult = myFF.Result
    ThatDoc.Activate
    Selection.TypeText Text:=FFResult
    Selection.TypeParagraph
    ThisDoc Activate
Next
Set ThisDoc = Nothing
Set ThatDoc = Nothing
End Sub


This could be trimmed down, but as I don't know exactly what you have, it is ahrd to say. If you have other formfields, you can test for what they are by using the Type property of the FormField collection. Textboxes are type 70.

You could also build a string, appending the results from each textbox. However, I have it passing the result from each formfield independently. It may be safer that way.

Gerry
See my Paintings and Sculpture
 
Hi Steve,

The contents of FormField Textboxes should also be available from the Bookmarks so, if you have a naming standard you should be able to do something along these lines:
Code:
[blue]For I = 1 to 20
    myText = ActiveDocument.Bookmarks(“TextBox” & i)
    [green]’ Do whatever you want with the text[/green]
Next[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
This was great! You've both made me very happy.

Steve
"Love has no meaning, not where we come from
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top