PDA

View Full Version : Trying to create a form that can be manipulated by the user?



hhart
06-22-2016, 07:09 AM
Hi,

I am trying to write a form that can be filled out, not edited, but can still be modified to fit the request from the user. In the Data Collection section of the form, I want there to be a button labeled 'Add Display' that pastes another copy of the table (Display title... scaling) underneath the last one. There can be any number of displays, so I want my form to work for all situations. I tried to record a macro that built the whole table from scratch, but I can't figure out how to make an index or something that remembers where to stick the new table. Here is my form to give a better idea of what I'm trying to do.

Thanks for any help you can give, and if not, I'd also appreciate being steered in the direction of learning materials. 16446

gmayor
06-22-2016, 11:13 PM
There's a problem with the content controls in Table 2. If you delete the content of the first two rows in the second column of that table and re-insert the content controls, then the following macro will add a matching table (with cleared values) to the end of that section. If not you will get a protection error.



Option Explicit
Sub Add_A_Table()
'Graham Mayor - http://www.gmayor.com
Dim oRng As Range
Dim oTable As Table
Dim oNewTable As Table
Dim oCC As ContentControl
Set oRng = ActiveDocument.Range
Set oTable = ActiveDocument.Tables(2)
With oRng.Find
Do While .Execute(FindText:="ADDITIONAL CONTROLS:")
'oRng.InsertParagraphBefore
' oRng.Start = oRng.Paragraphs(1).Previous.Range.Tables(1).Range.End + 1
oRng.Collapse 1
oRng.InsertParagraphBefore
oRng.Style = "Normal"
oRng.ParagraphFormat.SpaceAfter = 0
oRng.Collapse 0
oRng.FormattedText = oTable.Range
Set oNewTable = oRng.Tables(1)
For Each oCC In oNewTable.Range.ContentControls
If oCC.Type = wdContentControlCheckBox Then
oCC.Checked = False
Else
oCC.Range.Text = oCC.PlaceholderText
End If
Next oCC
Exit Do
Loop
End With
lbl_Exit:
Set oRng = Nothing
Set oTable = Nothing
Set oNewTable = Nothing
Set oCC = Nothing
Exit Sub
End Sub