#1
|
|||
|
|||
Call value from previous form field
Hey there, im doing a form for physical assessments and have my first column as body location(A) and the second column(B) are the tests. once a location is selected from a drop down a list of test for that body region show up in the drop down field in the second column.
EX A1 B1 A2 B2 I want to make it possible so that if formfield A2 is left at the default value formfield B2 loads the list associated with the value of A1. This is kind of what i want but the coding is not right If formfield(A2).result = "default value" Then formfield(A2) = formfield(A1).result |
#2
|
||||
|
||||
Since you're using Office 2013, I'd recommend eschewing formfields and using content controls. With these, some custom Quick Parts (building blocks) and a bit of code, you can have Word conditionally insert the desired dropdowns without having to code for populating them as well. Conditionally inserting & populating dropdown formfields takes a whole lot more work.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
so how would one go about doing that? lol
|
#4
|
||||
|
||||
First, you would need to create each of your dependent dropdown content controls, each in its own paragraph. Then you would create a custom Quick Part from each of those paragraphs (see http://office.microsoft.com/en-us/wo...010370568.aspx). Next, you'd delete those from the document and create the dropdown you'll use to choose the various options. Then, insert a continuous Section break immediately before where the dependent dropdown is to be inserted. Finally, you'd add a macro to the document's 'ThisDocument' module, coded along the lines of:
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim StrNm As String With ContentControl If .Title <> "Dropdown 1" Then Exit Sub Select Case .Range.Text Case "Item 1": StrNm = "Fruit" Case "Item 2": StrNm = "Game" Case Else: StrNm = "" End Select End With With ActiveDocument.Sections(2).Range.ContentControls(1) .LockContentControl = False .Delete End With If StrNm = "" Then Exit Sub Application.Templates("C:\Users\" & Environ("UserName") & _ "\Documents\Misc\Office Config\Word\Normal.dotm"). _ BuildingBlockEntries(StrNm).Insert RichText:=True, _ Where:=ActiveDocument.Sections(2).Range.Characters.First End Sub • "Dropdown 1" is the title property of the master dropdown • "Item 1" & "Item 2" are the master dropdown entry names • "Fruit" & "Game" are the corresponding custom Quick Part names. • the custom Quick Parts are stored in Word's 'Normal' template. • the target Section is Section 2.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
thanks for the answer, but which part of the code addresses the issue of calling back to the previous value from cell A1 if A2 is blank?
|
#6
|
|||
|
|||
Seems there is confusion between "formfield A2" and CELL A2. You asked about formfields NOT cells.
|
#7
|
|||
|
|||
My bad, yes i ment formfield, sorry im still new to the forums and have to make sure i use the proper wording
|
#8
|
||||
|
||||
As I advised in my previous reply:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Form field selection allows entry into form text box | David C | Word | 1 | 10-24-2012 04:53 AM |
Can't tab from field to field in form | Lynieee | Word | 6 | 06-18-2012 02:37 PM |
Word form field | JBaker | Word | 18 | 03-22-2012 09:05 AM |
Form Fields - Create blank form text field with if statement? | LAssist2011 | Word | 5 | 12-14-2011 03:02 PM |
Form Field Shading. | Ninerhoss | Word | 0 | 11-23-2010 02:40 PM |