auto populate a field based on values in other fields

S

sam

I have three fields where I want to auto populate a field (that has specific
values listed in a drop down menu) based on two other fields (both are
dropdown menus with specific values)

For Eg.:
there are 3 fields A, B, C and all these three fields have specific values
which we can select through a drop down menu. Now, Lets say values in the
fields are as follows:

A: 1, 2, 3, 4, 5
B: 1, 2, 3, 4, 5
C: a, b, c

So now, If I select '1' for A and '1' for B then I DONT want any thing to
populate in C and leave it blank.
If I select '1' for A and '2' for B then I want 'a' to be populated in C
If I select '2' for A and '1' for B then I want 'b' to be populated in C
If I select '1' for A and '1' for B then I want 'c' to be populated in C

Basically,
If the value in field A is smaller then field B then I want 'a' to be
populated in C.
If the value in field B is smaller then field A then I want 'b' to be
populated in C.
If the value in field A and B are equal then I want 'c' to be populated in C.

Hope I made it clear enough.

Thanks in Advance.
 
D

Doug Robbins - Word MVP

What type of form is this? Assuming that it is a document that is protected
for forms and that you have two dropdown formfields A and B and a textinput
formfield C, the running a macro containing the following code on exit from
A and B will populate C with the required result

Dim A As Long, B As Long, Diff As Long
With ActiveDocument
A = .FormFields("A").DropDown.Value
B = .FormFields("B").DropDown.Value
Diff = A - B
Select Case Diff
Case 0
.FormFields("C").result = "c"
Case Is < 0
.FormFields("C").result = "b"
Case Else
.FormFields("C").result = "a"
End Select
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
S

sam

Hi Doug,

Thanks a lot for the help.

Actually Its an excel form ( sorry to post here). I dont know much about
macros.

The idea is to auto populate one field based on values selected in two other
fields.

Lets say there are 3 fields A, B, C with specific values listed as a drop
down menu.

A: Hello, What, Going, There
B: Did, Jolly, Cool, Tomorrow
C: Discrepancy

so lets say for eg, If Hello and Did are selected, C will remain blank

If Hello, Jolly are selected, C will populate Discrepancy
(assume Hello has lower rating then Jolly)

If What and Did are selected, C will remain blank.

The Idea is, values in A and B column are text values and they have ratings.

If value in A has lower rating then value in B then populate 'discrepancy'
in C
If value in A has higher rating then value in B then no value is populated
in C
If A and B have the same values then no value is populated in C

And so on.. I hope it is clearer now?

Thanks in Advance
 
D

Doug Robbins - Word MVP

How are the ratings determined (Hello=Did, Hello<Jolly)?

I suggest that you should post your question to an Excel Newsgroup, not one
that deals with the use of VBA in Word.

However, If you want someone to help you, you must give the real information
and not assumptions!

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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