Form Fields

A

airhockeycanada

I am working with Microsoft Word 2002. I have a form created. One of the
fields is a drop-down list with 5 selections. These selections are sales rep
codes. We have another field which displays the sales rep name. What I want
to do is when a sales rep code is selected from the drop-down list, I want
the corresponding sales rep name to appear in the sales rep name field.

How do I accomplish this? I am not knowledgeable about VB at all. I have
tried using the Insert, Field and using an IF command but, ran into a
roadblock when it didn't seem to work and not sure what I'm doing wrong.

Thanks for your help on this in advance.
 
S

Suzanne S. Barnhill

You'll need nested IF fields. See the "Specify multiple conditions" portion
of the Help topic "Examples of IF fields."
 
A

airhockeycanada

Well, I did try that and it didn't work. I know it's something I did wrong
but, not sure what. This is what the Help topic states to do and I believe
this is in the field where the rep's name would appear:

{IF {MERGEFIELD State} = "CA" "For California residents, we offer special
rates to Asia and Japan." "{IF {MERGEFIELD State} = "WA" "For Washington
residents, we offer special rates to Asia and Japan." " "} "}

So, I did the following (by the way I have bookmarked my rep code field
RepCode):

{IF {MERGEFIELD RepCode} = "100" "Dave Smith" "{IF {MERGEFIELD RepCode} =
"101" "Sue Worthy" " "} "}

As an added problem, my RepCode bookmark seems not to be saving. When I
bring up the file again and check that the field is still bookmarked as
RepCode the bookmark is empty. Why is it not saving?

Finally, when adding an IF field the allowable space for the IF string is
not long enough for me to check for all our rep codes. Is there a solution to
this?

Thanks.
 
S

Suzanne S. Barnhill

Your problem is that you're using form fields, not merge fields. What you
want is just the bookmark name, and note that a form field has a built-in
bookmark (which you can modify in the Form Field Options); you don't have to
insert a bookmark manually, and in fact if you do, it will likely be
overwritten when the field is used. Try setting the built-in bookmark to
RepCode, then using the field { IF RepCode = "100" "Dave Smith" "{..., etc.
 
G

Graham Mayor

Suzanne has largely covered this, but the conditional field does not put the
information in another form field. To do that you will need to use vba. To
use conditional fields, they must go in the body of the document and the
calculate on exit check box property of the RepCode form field must be
checked. This will update the conditional fields but not if it is in the
header or footer. For those to update you will need to run a macro on exit
from the form field. I recommend also that you don't nest the fields but
concatenate them e.g.
{IF {REF State} = "CA" "For California residents, we offer special rates to
Asia and Japan."}{IF {REF State} = "WA" "For Washington residents, we offer
special rates to Asia and Japan."}etc

and

{IF {REF RepCode} = "100" "Dave Smith"}{IF {REF RepCode} = "101" "Sue
Worthy"}etc

then lock the form to allow the form fields to work.

If you want to run update code on exit from a field you'll find suitable
code at http://www.gmayor.com/installing_macro.htm

If you want to populate a form field (here shown as bookmark name RepName)
based on the content of a dropdown field (bookmark name RepCode) using vba
then you need something similar to the following, run on exit from the
dropdown field RepCode.

Sub OnExitRepCode()
'fills text form field based on content of a form field

Dim oFld As FormFields
Set oFld = ActiveDocument.FormFields
Select Case oFld("RepCode").Result
Case Is = "100"
oFld("RepName").Result = "Dave Smith"
Case Is = "101"
oFld("RepName").Result = "Sue Worthy"
Case Else
'Do nothing
End Select
End Sub


similarly the State version

Sub OnExitState()
Dim oFld As FormFields
Set oFld = ActiveDocument.FormFields
Select Case oFld("State").Result
Case Is = "CA"
oFld("Offer").Result = "For California residents, we offer special rates
to Asia and Japan."
Case Is = "WA"
oFld("Offer").Result = "For Washington residents, we offer special rates
to Asia and Japan."
Case Else
'Do nothing
End Select
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

airhockeycanada

Honestly, I thought this would be a little easier. I appreciate the help but,
it is sounding like Greek to me. I have checked the Help topic on this and
it's not registering. This seems like a ton of work simply to have a field
place a rep's name in it based on a rep code selected in another field.
 
S

Suzanne S. Barnhill

It shouldn't be difficult provided you're putting the IF fields in text in
the body of the form; if I read Graham's answer correctly, it's only if
you're trying to put them in the header or footer (or another form field)
that it becomes complex (requiring macros).

I experimented with this, however, and found that, in this application, the
bookmark alone doesn't work: you do need a REF field as Graham suggests
(i.e., { REF RepCode } instead of just RepCode). Also, you have to tab out
of the dropdown field before the IF field will update. If you just select
something from the dropdown and don't tab (for example, if you select
another form field with the mouse), the "Calculate on exit" feature doesn't
work.
 
G

Graham Mayor

You read correctly ;)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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