Consulting

Results 1 to 2 of 2

Thread: Build multiple tables and populate with variable data

  1. #1

    Build multiple tables and populate with variable data

    Hi Guys,


    I wondering about best approach.


    My use case is that I want to create a letter to my clients that contains information about insurance policy(ies) that I have arranged for them. From a data perspective I have a one to Many relationship between a policy and what it covers. One policy can have multiple coverages.


    For example, policy 1234 could have some Life Insurance and some Critical Illness Insurance.


    Each policy has a set of variables:
    Provider name
    Policy number
    Premium basis (guaranteed or reviewable)
    Monthly premium
    Reasons why the provider was chosed


    Each coverage has:
    Cover type (life, critical illness etc)
    Sum assured
    Term (how long the policy lasts)
    Options (any additional options added to the plan - there are many)
    Persons covered
    Exclusions and limitations
    Reasons why the coverage was designed the way it was


    My goal is to be able to "build" the table for each policy and associated coverage based on a user input form. For other aspects of the letter, I have achieved this to good affect.


    So far, I have built the table layouts for policy and coverage as quick parts, and indeed some of the narrative text within which are various content controls:

    Capture.jpg


    I'm wondering how best to approach the automatic creation of a table such as the one above using VBA to append the correct quick parts (policy and coverage) to the document and then autofill the content controls within the table.


    My thinking is that my VBA form will need a place for the user to enter how many policies have been sold, and for each, how many coverages are associated.


    I would then need an additional form per policy to record the specific data about that policy.


    I assume I would need some sort of loop to repeat the data entry section for each policy and associated coverage.


    My worry is about how Word references content controls or bookmarks. My understanding is that these require unique names so they can be referenced correctly.


    As my Quick Part contains the content controls, if there is more than one policy or coverage, then I'd have duplicate content controls in the document. Is this a problem?


    From previous learning of how to append quick parts and update content controls and bookmarks, I think I can fumble may way through this, but was hoping for a steer in the right direction, before I start coding.


    Many thanks,
    Stuart

  2. #2
    While bookmarks must have unique names, content controls do not have to have unique names and you can populate them all at the same time e.g.

    Dim oCC As ContentControl
        For Each oCC In ActiveDocument.ContentControls
            Select Case oCC.Title
                Case Is = "Name"
                    oCC.Range.Text = "Client Name"
                    'etc
                Case Else
            End Select
        Next oCC
    You may findhttps://www.gmayor.com/insert_content_control_addin.htm useful
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •