Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #13  
Old 04-08-2013, 03:37 PM
joyfulincanada joyfulincanada is offline Delete Current Row in protected Form Windows 7 64bit Delete Current Row in protected Form Office 2010 64bit
Novice
Delete Current Row in protected Form
 
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Current Row in protected Form Delete Rows in Protected Table with Form Fields Elan05 Word VBA 23 09-11-2014 12:47 PM
Mail Merge a Protected Form Maintaining Form Fills t/korean85 Word 1 04-07-2013 05:34 PM
Delete Current Row in protected Form Running a Macro in a protected form yessmarie Word VBA 1 05-25-2012 12:04 AM
Delete Current Row in protected Form Form protected in design mode-can't do anything DrDtMM Word VBA 12 01-23-2011 12:37 PM
Font size changes in a protected form..? jackbkmp Word VBA 0 03-03-2010 10:14 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:50 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft