![]() |
|
![]() |
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
![]()
I am using legacy fields to create a form in Word 2010. There will be well over 50 different fields in this form but I am focusing on about half. I have tried searching around the web for answers to my questions but have been unable to return any results.
I learn as I go so and I work on these forms when my workload is slow so it will sometimes be months before I can revisit a project; thus, my knowledge is quite limited. So the more descriptive the answer, the better J I have 3 questions in total: 1. How do I auto-populate multiple dropdown lists (w/ the same selections) based on the selection of 1 dropdown list? Thus far, I have successfully created a dropdown list that has auto-filled a second dropdown list further down on the same page but I cannot figure out how to duplicate this dependent dropdown. Action: Select option from first/main Dropdown “ddLocation” (12 choices) Result: Dependent Dropdown1 “ddRequestor” auto-populates with 3 choices Dependent Dropdown2 “ddRequestor1” auto-populates with the same 3 choices Dependent Dropdown3 “ddRequestor2” auto-populates with the same 3 choices … etc. 2. How do I auto-populate a text field/dynamic variable AND a dependent dropdown list at the same time? Action: Select item from “ddLocation” Result: Text Form Field “CC” (or DocVariable “{DocVariable CostCenter}”) auto-populates “ddRequestor”, “ddRequestor1”, etc. auto-populates 3. How do I auto-populate multiple text fields based on the selection of a dependent dropdown? Action: Select option from “ddRequestor” Result: Text Field “Req_Tel” auto-fills Text Field “Approver” auto-fills Text Field “Appr_Tel” auto-fills I’d prefer not to use DocVariables for this section since I will have a total of 25 unique selection options for the dependent dropdowns which would total the number of lines to 75. Currently, I have a table hidden at the bottom of my document which I would like to use, if possible. Also, if there is a way to use this table (I can add another column with the locations & one more row for each location) as the source for the dependent dropdown lists as opposed to the VBA code, that would be ideal that way, in case of personnel change, there is only one location that would have to be edited instead of two. While ideal, this is not required. I’ve attached a sample of the form I am working on. I left only the formfields that need to be populated through vba. The code I have is from Greg Maxey’s demo pack. (http://gregmaxey.com/word_tip_pages/link_content_to_dropdown_list.html) Thanks in advance for any and all help! |
#2
|
||||
|
||||
![]()
This code addresses question 1. It avoids the use of document variables since you are coding the values in vba anyway.
Note there is a significant failing on the original code which is continued in this improvement. If you have completed the form and then revisit the first field, you will reset all the requestor fields. To avoid this, your code will need to run ONLY when the value in Location CHANGES rather than simply when you exit this field. This would be easy to avoid if you used Content Controls instead of legacy docs since they have an OnChange event. With legacy form fields we would need to store the initial value and compare it to final value to work out whether it has changed while the user was in the field. Code:
Sub Form_DD_OnExit() Dim oFF As FormField, lngIndex As Long, oDoc As Word.Document, i As Integer Dim arrLocation() As String, strPassword As String, arrReqFields() As String Set oDoc = ActiveDocument Set m_oFF = Selection.FormFields(1) arrReqFields = Split("ddRequestor|ddRequestor1|ddRequestor2|ddRequestor3|ddRequestor4", "|") Select Case m_oFF.Name Case "ddLocation" If m_oFF.DropDown.Value > 1 Then arrLocation = GetRequestors(m_oFF.Result) For i = LBound(arrReqFields) To UBound(arrReqFields) With oDoc.FormFields(arrReqFields(i)).DropDown .ListEntries.Clear For lngIndex = 0 To UBound(arrLocation) .ListEntries.Add arrLocation(lngIndex) Next lngIndex .Value = 1 End With Next i End If End Select Set oDoc = Nothing lbl_Exit: Exit Sub End Sub Function GetRequestors(sState As String) As String() Dim sReq As String Select Case sState Case "Maine" sReq = "Adams, John|Brown, John T.|Clark, John J." Case "New Hampshire" sReq = "Davis, John|Evens, John F.|Clark, John J." Case "Vermont" sReq = "Fisher, John S.|Green, John T.|Clark, John J." Case "Massachusetts" sReq = "Hill, John|John|Irwin, Clark J." Case "Rhode Island" sReq = "Jones, John|Kelly, John R.|Clark, John J." Case "Connecticut" sReq = "Lee, Jane M.|Miller, John J.|Clark, John J." Case "New York" sReq = "Nelson, John G.|Olson, Jane G.|Clark, John J." Case "Pennsylvania" sReq = "Parker, John G.|Quinn, John R.|Clark, John J." Case "New Jersey" sReq = "Roberts, Jane M.|Smith, John F.|Gaffney, John J." Case "Delaware" sReq = "Thompson, John|Underwood, John|Clark, John J." Case "Maryland" sReq = "Vaughn, John|Williams, John P.|Clark, John J." Case "Virginia" sReq = "Xu, John|Young, John|Clark, John J." Case Else sReq = "None specified" End Select sReq = "Select Requestor|" & sReq GetRequestors = Split(sReq, "|") End Function
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
![]() |
Tags |
form fields, vba, word 2010 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Retain format in dropdowns when unlinking fields | brent chadwick | Word VBA | 2 | 09-08-2015 12:50 PM |
![]() |
ryebanana | Outlook | 1 | 07-21-2015 04:25 AM |
Populate Word Drop-down list with Excel column then auto fill form fields with Excel data | Faldinio | Word VBA | 7 | 10-19-2014 06:03 AM |
auto populate fields for multiple files w/in folder | jbyrd | Word | 0 | 07-21-2014 07:35 AM |
Auto-populate from form fields | kenelder | Word | 3 | 05-23-2013 07:50 AM |