#1
|
|||
|
|||
Dependent dropdown and repeat section
I have no experience with VBA and really limited experience using content controls. I'm helping to create a report template to use for approximately a year until we get into an electronic system. The goal is to create efficiency and make reports quicker and easier to complete. There are several content controls and one section to allow free text and lists and a dependent relationship between category and sub-category. The entire section should be repeatable as each report will have a varying number of observations to include. I have been able to modify a VBA code from another website which works for one observation, but this won't work for any additional observations whether I copy and paste or use the section repeat content control. I'm not sure if this makes sense, but I'm hoping that someone can help.
Code:
Sub PopulateddCategory() Dim xDirection As FormField Dim xState As FormField On Error Resume Next Set xDirection = ActiveDocument.FormFields("ddCategory") Set xState = ActiveDocument.FormFields("ddSub") If ((xDirection Is Nothing) Or (xState Is Nothing)) Then Exit Sub With xState.DropDown.ListEntries .Clear Select Case xDirection.Result Case "Business Continuity Disaster Recovery" .Add "Adherence" .Add "Documentation" .Add "Procedure" Case "Computerized Systems Management" .Add "Adherence" .Add "Documentation" .Add "Procedure" .Add "Validation" Case "Contract Agreement" .Add "Adherence" .Add "Documentation" .Add "Procedure" Case "Data Collection and Handling" .Add "Adherence" .Add "Documentation" .Add "Procedure" .Add "Source Data Verification" Case "Good Documentation Practices" .Add "Adherence" .Add "Procedure" Case "Records Management" .Add "Investigator Site File" .Add "Procedure" .Add "Trial Master File Master File" End Select End With End Sub Last edited by macropod; 01-11-2020 at 01:31 PM. Reason: Added code tags |
#2
|
||||
|
||||
Your code indicates you're using formfields, not content controls for the dropdowns. The two are entirely different. Moreover, you seem to have all the existing content inside a single rich-text content control. Bad idea. Content controls and formfields were not designed to be used together and trying to do so can lead to problems.
Your basic issue can be solved by using a Word table as a container, and a suitable macro to drive the process from the last formfield or content control in that table. You will, of course, need to rename your formfields and modify your existing code to continue working with those. The advantage of using content controls, on the other hand, is that they don't require document protection to work (though that can be used) and don't require each new set to be renamed. For code that works by adding a new row to a table in a document with formfields: Macro to add row to table in a Word form For code that works by adding a new row to a table in a document with content controls: Code to add new row in table Macro to add row to table in a Word form https://www.msofficeforums.com/word-...tml#post145675
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thank you for the advice and noting my misinformation. I'll do additional research on the basic cc/forms and then try to apply the advice you've given.
Are there any online courses or references that would be helpful to someone like me that knows nothing, but would like to learn more about VBA (word and excel)? I see this as a very powerful tool that I could apply for efficiency. Thanks again |
#4
|
||||
|
||||
I am not aware of any on-line courses that would be worthwhile. But, then, I also don't spend time reviewing them...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
dependent vba |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Content Controls - Dependent Dropdown | someazguy | Word VBA | 14 | 02-05-2023 08:01 PM |
Multiple dependent dropdown lists in table with add new row option | jeweldarby | Word VBA | 6 | 05-21-2022 04:37 PM |
Dropdown Menu Dependent on a Previous Drop Down | lgsikaffy | Word VBA | 3 | 12-14-2018 05:14 PM |
Dropdown dependent text | JakeLRL | Word VBA | 7 | 04-07-2016 08:26 AM |
make text form field active dependent on dropdown | Glenn0004 | Word VBA | 1 | 06-23-2015 06:13 PM |