View Single Post
 
Old 04-08-2013, 03:37 PM
joyfulincanada joyfulincanada is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Apr 2013
Posts: 7
joyfulincanada is on a distinguished road
Default

Posting one last time to say, alternate solutions to my problem, to remove the bottom row of my table and add a row at the top, or to migrate the table rows down:

Migration solution (from macropod's macro):
Code:
Sub MigrateReversed()
    Dim i As Long, j As Long, bRslt As Long
    Application.ScreenUpdating = False
    bRslt = MsgBox("Do you want to delete old data?", vbYesNo)
    If bRslt = vbNo Then Exit Sub
    With Selection.Tables(1)
      For i = .Rows.Count To 2 Step -1
        For j = 1 To .Rows(i).Cells.Count
          If i > 2 Then
            .Cell(i, j).Range.FormFields(1).Result = _
                .Cell(i - 1, j).Range.FormFields(1).Result
          Else
            .Cell(i, j).Range.FormFields(1).Result = ""
          End If
        Next
      Next
    End With
    Application.ScreenUpdating = True
End Sub
Deletion/addition solution (from Doug Robbins and HansV):
Code:
Sub AddRow()
    Dim oTable As Table
    Dim Response As String
    Dim CurRow As Row
    Dim i As Long
    Dim fCount As Long
    Dim ff As FormField
    Dim sPassword As String
    Set oTable = Selection.Tables(1)
    sPassword = "flower"
    'Define the password used to protect the form (if any)
    Response = MsgBox("Do you want to delete the last row?", vbQuestion + vbYesNo)
    'Ask user about deleting last row
    With ActiveDocument
        If Response = vbYes Then
            .Unprotect Password:=sPassword
            'Unprotect document
            oTable.Rows(oTable.Rows.Count).Delete
            'Delete last row
            .Protect NoReset:=True, Password:=sPassword, _
                Type:=wdAllowOnlyFormFields
            'Reprotect the form
        End If
        Response = MsgBox("Do you want to add a new row?", vbQuestion + vbYesNo)
        'Ask user about adding new row
        If Response = vbYes Then
            .Unprotect Password:=sPassword
            'Unprotect document
            Set CurRow = oTable.Rows.Add(BeforeRow:=oTable.Rows(2))
            For i = 1 To CurRow.Cells.Count
                Set ff = .FormFields.Add(Range:=CurRow.Cells(i).Range, Type:=wdFieldFormTextInput)
                With ff
                    .Name = "col" & i & "row2"
                    'Add a unique bookmark name
                    .Enabled = True
                    'Enable the field for user entry
                    .CalculateOnExit = True
                    'set the calculate on exit check box
                End With
            Next i
            .Protect NoReset:=True, Password:=sPassword, _
                Type:=wdAllowOnlyFormFields
            'Reprotect the form
            CurRow.Cells(1).Range.FormFields(1).Select
            'Select the first field in the new row
        End If
    End With
End Sub
See the following link for the other thread on this:
http://answers.microsoft.com/en-us/o...e-6bce18db44a2

As they do slightly different things, I am going to show both to the people who will be using my form and see which one they prefer.

Thanks for all your help! I hope this is helpful to someone else also.

Last edited by macropod; 04-08-2013 at 03:42 PM. Reason: Added code tags & formatting
Reply With Quote