vba + forms: copying fields, etc

D

d. williams

hello, i figured this would qualify as newbie material. i have two quesitons regarding a template i set up which uses forms.

1. i would like to have the user set their name into a text field and then have what they typed copied into the header of the document. i wrote a basic script that copies the value into another text field, however, i can't insert any fields into the header.

2. one of the items is a drop-down box from which the user selects several options. i would like a paragraph beneath the box to change based on the user's selection. i was wondering what is the most common way to do this. i have a working solution by placing a second field beneath the drop-down for the paragraph. a script runs at the exit from the drop-down which sets the paragraph field's text. while this has the benefit of allowing the user to change the paragraph if absolutely necessary, i don't like having the actual text stored only in the macro code. is there a way to toggle the visibility of a field (ie user selects choice 2, so only paragraph 2 shows and all other disappear)? is there just a better way to do this?

3. is there a general vba for word api out there? i tried running some searches, but nothing terribly helpful came up.

thanks for any help. d.
 
D

Doug Robbins - Word MVP

Hi d,

For item 1, use a cross reference to the text of the bookmark assigned to
the formfield. Set the Calculate on exit property for the formfield so that
the fields in the document are updated after the user enters the data into
the field.

For item 2, create each paragraph as an autotext entry with the name of the
entry corresponding to the items in the dropdown form field. Then use a
macro containing code similar to the following on exit from the formfield to
populate a formfield with the paragraph corresponding to the item selected
in the dropdown:

' Macro created 15-11-97 by Doug Robbins to add the address corresponding to
a drop down name
'
Set myDrop = ActiveDocument.FormFields("Dropdown1").DropDown
Company = myDrop.ListEntries(myDrop.Value).Name
Address = ActiveDocument.AttachedTemplate.AutoTextEntries(Company).Value
ActiveDocument.FormFields("Text1").Result = Address

I don't understand question 3.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
hello, i figured this would qualify as newbie material. i have two
quesitons regarding a template i set up which uses forms.

1. i would like to have the user set their name into a text field and then
have what they typed copied into the header of the document. i wrote a
basic script that copies the value into another text field, however, i can't
insert any fields into the header.

2. one of the items is a drop-down box from which the user selects several
options. i would like a paragraph beneath the box to change based on the
user's selection. i was wondering what is the most common way to do this.
i have a working solution by placing a second field beneath the drop-down
for the paragraph. a script runs at the exit from the drop-down which sets
the paragraph field's text. while this has the benefit of allowing the user
to change the paragraph if absolutely necessary, i don't like having the
actual text stored only in the macro code. is there a way to toggle the
visibility of a field (ie user selects choice 2, so only paragraph 2 shows
and all other disappear)? is there just a better way to do this?

3. is there a general vba for word api out there? i tried running some
searches, but nothing terribly helpful came up.

thanks for any help. d.
 
B

Brian

hello, i figured this would qualify as newbie material. i have two
quesitons regarding a template i set up which uses forms.

1. i would like to have the user set their name into a text field and then
have what they typed copied into the header of the document. i wrote a
basic script that copies the value into another text field, however, i can't
insert any fields into the header.

You don't need VBA script to do this. You can simply insert a field in the
header with a reference to the bookmark.

In the header, Choose Field from the Insert menu. Select the Links and
References category then select Ref from the Field names. Click the options
button then the Bookmarks tab. Add the bookmark the contains the user's
name.

One quirk with this is that if you are using the form in Page Layout view,
the header does not automatically update after entering or changing text in
the user name text box. If you save the document then re-open it, the
header will be updated.

Another work-around is to enter the form field info with the document in the
Normal view. When you go to print it or switch to Page Layout view, the
header will be updated.

-Brian
 
D

d. williams

thank you for the adivce, it works wonderfully. one quick followup question: is there a way to trigger the subroutine when the user selects an item from the dropdown, not just when they exit the field? thanks, again. d.
 
D

Doug Robbins - Word MVP

Hi d,

No, with formfields, the only events that you have to fire a macro are Entry
and Exit.

With a userform, there are more possibilities.

See the article "How to create a Userform" at:

http://www.mvps.org/word/FAQs/Userforms/CreateAUserForm.htm

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
thank you for the adivce, it works wonderfully. one quick followup
question: is there a way to trigger the subroutine when the user selects an
item from the dropdown, not just when they exit the field? thanks, again.
d.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top