﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>A1VBCode Forums / Classic Visual Basic (VB 6 or earlier) / VBA(Excel, Word, etc...)  / Need code for expanding Word table rows with copied default formfields / Latest Posts</title><generator>InstantForum.NET v4.1.1</generator><description>A1VBCode Forums</description><link>http://www.a1vbcode.com/vbforums/</link><webMaster>forums@a1vbcode.com</webMaster><lastBuildDate>Thu, 09 Feb 2012 04:36:43 GMT</lastBuildDate><ttl>20</ttl><item><title>Need code for expanding Word table rows with copied default formfields</title><link>http://www.a1vbcode.com/vbforums/Topic28712-14-1.aspx</link><description>I'm working on a Word template (form) that contains tables having a mix of formfields such as textinput, dropdowns, and checkboxes.  I would like to provide a single default data row for each table, but if the user enters valid data in the first cell of the last row, the table expands with a new default row below the active cell the user just filled in. The following code is latest draft for a table where default textinput for cell(1) is "nn", but requires at least two data rows and is not smart enough to know if another default row is available below the active (selected) cell:&lt;/P&gt;&lt;P&gt;Sub AddRow()&lt;BR&gt;    Dim thisDoc As Document&lt;BR&gt;    Set thisDoc = ActiveDocument&lt;BR&gt;    Dim oTable As Table&lt;BR&gt;    Dim oCell As Cell&lt;BR&gt;    Dim oPrevRow As Row, oNewRow As Row&lt;BR&gt;    Dim tmp&lt;BR&gt;    'Unprotect Document&lt;BR&gt;    If thisDoc.ProtectionType &amp;lt;&amp;gt; wdNoProtection Then&lt;BR&gt;        thisDoc.Unprotect&lt;BR&gt;    End If&lt;BR&gt;   &lt;BR&gt;    tmp = Selection.Text&lt;BR&gt;    If tmp &amp;lt;&amp;gt; "nn" Then&lt;BR&gt;        If tmp &amp;lt;&amp;gt; "n" Then&lt;BR&gt;        'Selection.FormFields(1).TextInput.Clear&lt;BR&gt;            ' Copy last row&lt;BR&gt;            Set oTable = thisDoc.Tables(10)&lt;BR&gt;            Set oPrevRow = oTable.Rows(oTable.Rows.Count)&lt;BR&gt;            oPrevRow.Range.Copy&lt;BR&gt;            Set oNewRow = oTable.Rows(oTable.Rows.Count)&lt;BR&gt;            ' Copy last row to new row&lt;BR&gt;            oNewRow.Range.Paste&lt;BR&gt;            &lt;BR&gt;        End If&lt;BR&gt;    End If&lt;BR&gt;    'Protect Document&lt;BR&gt;    If thisDoc.ProtectionType = wdNoProtection Then&lt;BR&gt;        thisDoc.Protect wdAllowOnlyFormFields, NoReset:=True&lt;BR&gt;    End If&lt;BR&gt;End Sub&lt;/P&gt;&lt;P&gt;I also would like to ensure that the formfields in the new row are reset to their default values without resetting the entire form.</description><pubDate>Tue, 19 Jan 2010 15:34:52 GMT</pubDate><dc:creator>SeefDawg</dc:creator></item></channel></rss>
