Know your ISP.

User #77055   1890 posts
Whirlpool Enthusiast

I have a form, and want to add default text to particular fields in the form at the click of a button. Is this possible?

If not, is it possible with another programs which allow creation of forms - like adobe etc?

posted 2008-May-14, 7pm AEST
User #2044   7399 posts
Whirlpool Forums Addict

Give the fields unique ID's and in the button press function assign your text to the .text method(?).

posted 2008-May-14, 8pm AEST
User #77055   1890 posts
Whirlpool Enthusiast

mce writes...

Give the fields unique ID's
done
in the button press function assign your text to the .text method(?).

??????? i lost u here

posted 2008-May-14, 8pm AEST
User #2044   7399 posts
Whirlpool Forums Addict

What have you got so far?

posted 2008-May-14, 8pm AEST
User #77055   1890 posts
Whirlpool Enthusiast

mce writes...

What have you got so far?

i can have default values for each field....but the problem i have is....i dont want the default values to display unless i tell it to display...

for example, i would like:

a check box which says: "prefill fields" which when checked automatically fills in the default values for each of the fields in the form.....

this way i avoid repetition.

so far i have a form, with all default values entered into the properties of each field... but they are all showing up wen i open the form. i want a way to control when to show these default values.

posted 2008-May-15, 12pm AEST
edited 2008-May-15, 12pm AEST
User #77055   1890 posts
Whirlpool Enthusiast

tried to create a macro, but didnt work.

posted 2008-May-17, 12pm AEST
User #28640   379 posts
Forum Regular

Not sure which language/IDE you are using for this, but maybe when loading a page set them all to empty, and when prefill is clicked loop through the fields and get their default values and set them?

posted 2008-May-17, 12pm AEST
User #77055   1890 posts
Whirlpool Enthusiast

Mihan writes...

Not sure which language/IDE you are using for this, but maybe when loading a page set them all to empty, and when prefill is clicked loop through the fields and get their default values and set them?

not using any programming language. just using the forms feature on microsoft word.

posted 2008-May-17, 4pm AEST
User #30842   2528 posts
Whirlpool Forums Addict

I have to say your question is so vague, that even asking for clarification invites misunderstanding.

Assuming you want to add text to text boxes in word (not fields in word which are different, and I dont know how to update fields programmically)

Behind your command button in the onclick event type

me.textbox1.text = "Default stuff here"

Where textbox1 is the name of your text box.

I am assuming you know how to add form controls, and move in and out of design mode.

posted 2008-May-17, 5pm AEST
User #77055   1890 posts
Whirlpool Enthusiast

myobman writes...

Behind your command button in the onclick event type

me.textbox1.text = "Default stuff here"

Where textbox1 is the name of your text box.


i see. u are suggesting the usage of control toolbox and its features. i will try this.

Assuming you want to add text to text boxes in word

all i did was create a form using word which has checkboxes, text areas, and drop down menus.

i did not use the control toolbox.

posted 2008-May-17, 6pm AEST
User #77055   1890 posts
Whirlpool Enthusiast

myobman writes...

me.textbox1.text = "Default stuff here"

me.textbox1.text does not seem to work. the me.textbox1 one bit is recognised, but the last bit: ".text" seems to throw an error.

posted 2008-May-17, 6pm AEST
User #77055   1890 posts
Whirlpool Enthusiast

correction: it works, but only if the whole form is created using control tools, rather than form tools.

is there a way to make it work using just form tools.

posted 2008-May-17, 6pm AEST
edited 2008-May-17, 6pm AEST
User #30842   2528 posts
Whirlpool Forums Addict

Assuming you are using, what you call a control tool, then I guess you have to use bookmarks. Using bookmarks for user entered text is not a good idea, as they will delete the bookmark.

Insert your bookmark where the field is.

Private Sub CheckBox1_click()
If ActiveDocument.Bookmarks.Exists("a­ ddress1") = True Then

If Me.CheckBox1.Value = True Then
Selection.GoTo What:=wdGoToBookmark, Name:="address1"
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.InsertAfter "This is the new text"
ActiveDocument.Bookmarks.Add Range:=Selection.Range, _
Name:="address1"
Else
Selection.GoTo What:=wdGoToBookmark, Name:="address1"
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.InsertAfter "[Click here and type address]"
ActiveDocument.Bookmarks.Add Range:=Selection.Range, _
Name:="address1"

End If
End If
End Sub

Me I would just use a text box. To me that is what a PROPER form field is. Words form fields, other than the ones that Update are just plain evil.

The user cant delete it, can type in it till he is blue in the face, and you have full control on what it looks like.

Of course I dont know much about form fields, other than a few basic ones like the date.

posted 2008-May-18, 12am AEST
edited 2008-May-18, 12am AEST
User #77055   1890 posts
Whirlpool Enthusiast

myobman writes...

Me I would just use a text box.

i tried that, but what i find is that i need to define the text area....and if the number of words/lines exceeds this text area, then when i print it - the rest of the text does not appear.

in addition the text area does not allow users to have dot points, or create paragraphs. it all appears as one big paragraph.

thats why i have just used form fields....rather than control tools....

i.e.: view > toolbars > forms rather than view > toolbars > control toolbox.

but with the form text fields, i am yet to find a way to implement the default values only when i specify.

posted 2008-May-18, 12pm AEST
edited 2008-May-18, 12pm AEST
User #77055   1890 posts
Whirlpool Enthusiast

eureka, i foudn this article:

pubs.logicalexpressions....ticle.asp?ID=806

now, i want a very similar thing and that is: making one check box fill out default details for text fields.

i can use a similar principle, but i don't know the offical code lingo for "text fields".

for eg: for check box, its "CheckBox".

what is it for text fields.

posted 2008-May-18, 9pm AEST
edited 2008-May-18, 9pm AEST
User #3103   2165 posts
Whirlpool Forums Addict

Do you mean:

<input type="text" name="name" value="default text of the text box">

?

posted 2008-May-19, 1am AEST
User #30842   2528 posts
Whirlpool Forums Addict

AFAIK you reference fields in VBA by their bookmark name. I have given you some code for that.

Checkbox1 is not an official name for a checkbox, you can call it what your want. Its just microsofts default name for the first one you put on a page, you would normally rename it

chkMaster
chkQuest1 etc

You do understand this is a "programming" forum. A more interesting question might have been (and is germaine to your enquiry) is "How do I allow the user to type into a bookmarked field, without loosing the bookmark, so I can reference it later on?"

Dont know the answer to that one.

posted 2008-May-19, 10am AEST
User #77055   1890 posts
Whirlpool Enthusiast

myobman writes...

Checkbox1 is not an official name for a checkbox,

i mean in the following code:
blnMasterValue = ActiveDocument.FormFields("Check1"­ ).CheckBox.Value = True

isn't CheckBox the official name for a "checkbox", where "Check1" is the actual name as I put it for a check box. (tongue twister :-))

So instead of where it says: "CheckBox.Value = True"

I would like something where I can input default values such as (just as an example):
OfficialNameforTextField.Value = "Default Value blah blah".

posted 2008-May-19, 11am AEST
edited 2008-May-19, 11am AEST
User #77055   1890 posts
Whirlpool Enthusiast

Andrew A writes...

Do you mean:

<input type="text" name="name" value="default text of the text box">

?


i did try:
blnMasterValue = ActiveDocument.FormFields("Check1"­ ­ ).Text.Value = "Display the default value"

But it did not work.

posted 2008-May-19, 11am AEST
User #30842   2528 posts
Whirlpool Forums Addict

Me.CheckBox1.Value = True

Whats wrong with that? I have posted the code.

posted 2008-May-19, 12pm AEST
User #77055   1890 posts
Whirlpool Enthusiast

myobman writes...

Me.CheckBox1.Value = True

Whats wrong with that? I have posted the code.


nothign wrong with that if u wish to use active controls. but i am just using regular form fields.

u can create forms by two means in word: using controls or just regular form fields.

posted 2008-May-25, 11pm AEST
Hosted by
WebCentral Australia
Big numbers
983,170 threads
17,339,047 posts
2,021,543 whims sent
3,114 wiki topics
230 ISPs listed
8,099 broadband plans
829 modems & routers
40,940 features filled