need code to select one drop down option based on a previous drop

F

fiddleman

I am looking for the code to auto select a value on one form field from input
on a previous one. The form fields could be drop downs ....or as simple as
checkboxes.
i.e. if one checkbox is checked, I want the other to autocheck as well....or
its value to be true. If a certain selection is made in the first drop-down
box, a certain selection should be set in the second drop-down.
 
C

Chris Marlow

Hi,

You can use the 'Run macro on', 'Exit' on the Field Options dialog for the
form item to set a macro that sets the value in the other field. If I
remember rightly you set the Bookmark property of the field here to 'name'
the form field (so you access it through bookmarks).

Regards,

Chris.
 
G

Greg

Fiddle stroker,

Here is some examples of controling one text field with another, one
checkbox with another and one dropdown with another. You could of
course adapt a necessary:

Sub ROE()
Dim oFFld As FormFields
Set oFFld = ActiveDocument.FormFields
On Error Resume Next
ActiveDocument.Unprotect
On Error GoTo 0
If oFFld("Text1").Result = "Hello" Then
oFFld("Text2").Result = "World"
Else
oFFld("Text2").Result = " "
End If
If oFFld("Check1").CheckBox.Value = True Then
oFFld("Check2").CheckBox.Value = True
Else
oFFld("Check2").CheckBox.Value = False
End If
Select Case oFFld("DropDown1").Result
Case "A"
oFFld("DropDown2").Result = "Apples"
Case "B"
oFFld("DropDown2").Result = "Broomsticks"
Case Else
'Do nothing
End Select
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True
End Sub

To test, enter two text fields, two check boxes and two dropdowns in a
document. Enter A and B as options in the first dropdown.

Set the ROE macor to "Run on Exit" from the first text, checkbox, and
dropdown.

HTH
 

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