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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable name for forms control

Status
Not open for further replies.

MrBaRRon

Programmer
Aug 8, 2003
39
IT
Hi everybody,

I would like to set the value of a form control but dinamically. Example:

Currently I used this syntax: wrd.ActiveDocument.col_eur.Value = "TEST"

Is it possible to use this kind of syntax ?:

Dim num_control As Variant

num_control = 'the value of another field '

wrd.ActiveDocument.col_eur&num_control&.Value = "TEST"

Is there a good syntax to do as it ?

Thanks U
 
Yes, you certainly can set values dynamically. Could you please clarify

wrd.ActiveDocument.col_eur.Value = "TEST"

What is the object?



Gerry
 
Hi Gerry,

I have a Word document and depending on the number of client, a section within the document is copy and paste in the same document the same number of times as the number of client.

So the form controls are pasted with the same name but with an ioncremential numero, I mean the first textbox is "col_eur", the second "col_eur1", the first "col_eur3"...

So I would like to set the value of this controls but dinamically, with a syntax as

Dim nbre As String
wrd.ActiveDocument.col_eur& nbre.Value = "TEST"

It's the name of the textbox I want it becomes dinamical.

I have created this textbox with the classis tool box of Word. It's the first textbox type in this toolbox

Is it clear now ?

Tell me if you not understand what I want.


Thank U.
 
OK, ;et us make sure I have it.

You have a numbe rof textbox, already named. To make it simple;

text1, text2 text3 are their names

I am still confused, because there seems to be confusion bewteen Vlaue, and Name.

On one hand it appears you want to incement the object name and that make text1 = Value, text 2 = same value, text3 = same value.

If so, you call the object either b by index number, or explicitly by name. You can increase the name, by the number - just like the eample in your own post. You hsd the right idea. The only problem is that if the bookmark contains MORE stuf than the formfield, then it won't work. You would still have to explcitly grab the bookmarksd.

(Line 1) checkbox [COLOR=red yellow]"Bank Statement: " formfield[/color]
(Line 2) checkbox [COLOR=red yellow]"Pay Stub: " formfield[/color]

Checkbox is a formfield AND a bookmark (name for both the same)
formfield is a formfield AND a bookmark (name for both the same)

The highlight of the text AND the formfield is a bookmark (name = BankStatement)

Checkbox is a formfield AND a bookmark (name for both the same)
formfield is a formfield AND a bookmark (name for both the same)

The highlight of the text AND the formfield is a bookmark (name = PayStub)

Code:
Sub exportValue()
Dim sText1result As String
Dim aDoc As documrent
Dim newDoc As Document

Set aDoc = ActiveDocument
    Application.Documents.Add
Set newDoc = ActiveDocumentct

aDoc.Activate

sText1result = ActiveDocument.FormFields("Text1").Result
ActiveDocument.FormFields("text2").Result = sText1result  'set the result
ActiveDocument.FormFields("text3").Result = sText1result   'set the result

ActiveDocument.Bookmarks("BankStatement").Range.Select
    Selection.Copy
    newDoc.Activate
      Selection.Paste
    aDoc.Activate
ActiveDocument.Bookmarks("PayStub").Range.Select
    Selection.Copy
    newDoc.Activate
      Selection.Paste
    aDoc.Activate
Set newDoc = Nothing
Set aDoc = Nothing
End Sub

Hopefully, we are getting closer here.

Gerry
 
Thank U Gerry for your interest.

In fact , i Would like to do something like that:

ActiveDocument.FormFields("text3").Result = "TEST"

With ("text3") as variable, by example:

Dim namefield as string

namefield = Recordset("field_table")

ActiveDocument.FormFields("namefield").Result = "TEST"

I hope it's more cledar for you now,

thanks again.
 
Have you tried something like this ?
ActiveDocument.FormFields(namefield).Result = "TEST"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I have tried but it don't works. It is very surprising if their is not a good syntax no ?

Thank U for you help.
 
but it don't works
Any error message ?
Are you sure thay namefield is a string variable containing a valid formfield name in the active document ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
but it don't works" means it returns me that the object is not in the collection.It don't find any object with this name....

Thank U for your interest.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top