Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-06-2013, 07:07 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 Delete Current Row in protected Form

Hello,



Disclaimer: I am a complete novice to all of this.

I am reading this forum with interest as I am trying to set up a protected Word form also where the user can delete or add rows to an otherwise locked table. I found code on Graham Mayor's website which worked like a charm for adding a row to the table but I can't figure out how to delete a row.

Essentially, I have my entire form set up as a table, with form fields in the cells, and there is a sub-table within this form. When users are filling it out, essentially there are large text fields, and then this sub table for numbers to be entered. I want them to be able to delete rows in that table that are unused. So, if all the information is deleted from a row, I want that row to disappear.

Is this possible?

Thanks in advance!

P.S. I tried the code (https://www.msofficeforums.com/word-...rm-fields.html) and it doesn't delete rows from my table...

Last edited by macropod; 04-07-2013 at 05:25 PM. Reason: Split posts to new thread
Reply With Quote
  #2  
Old 04-07-2013, 12:08 AM
macropod's Avatar
macropod macropod is offline Delete Current Row in protected Form Windows 7 64bit Delete Current Row in protected Form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The code I posted is for deleting all rows from the last row upwards in the second table in the document where the first formfield on each row is empty. It exits at the first non-empty row. It is not for deleting the 'current' row. Whilst the code could be modified to delete just the current row, what you need to figure out is how you're going to trigger the macro only when you know there are no data to add to that row. When you've figured that out, please post your query in a new thread rather than hijacking a thread dealing with a different issue.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-07-2013, 08:54 AM
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

Hello,

As a complete newbie to all of this, I had no idea that my trying to ask a question I have been struggling with, and that I thought was related to the previous question, would be perceived as a 'threadjack'.

Apologies if I have somehow disrupted the culture of this forum by doing so, as your reply suggests.
Reply With Quote
  #4  
Old 04-07-2013, 05:30 PM
macropod's Avatar
macropod macropod is offline Delete Current Row in protected Form Windows 7 64bit Delete Current Row in protected Form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi joyfulincanada,

I've split your posts off to a new thread.

As indicated in my previous reply, the essential issue you need to address is how the code is to determine automatically that the current row is to be deleted. For example, when you create the document, the row of interest will, presumably, be empty, so you don't want to delete it at that stage. If you then enter a formfield on that row, and decide to exit without making any edits, should the code just assume you want to delete the row (risky IMHO)? If not, what are the rules?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 04-07-2013, 06:54 PM
macropod's Avatar
macropod macropod is offline Delete Current Row in protected Form Windows 7 64bit Delete Current Row in protected Form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted at: http://answers.microsoft.com/en-us/o...2-ca4fd5b67465
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 04-07-2013, 07:33 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

Hello,

Thanks for responding. I had asked on a different forum today as I was not sure I would get a response back here, and I do need to sort out my form as soon as possible. I have no idea how to code these things myself and no idea if I am even asking the questions the way I should.

What I need the table to do is this:
I need to have the four rows, each with a date, for example a row for april 2012, then a row for september 2012 below it, and a row for december 2012 below that and then a row for april 2013 below this. As users use my form, I want them to be able to specify to delete the top row (april 2012) so they can enter a new row (say for september 2012).

Yes, when I open my form, all four rows may be blank. I want to fill in one, or more, or all of them, and once i have filled in all of them, to add a new row and delete the oldest row, maintaining the four most recent rows. Ideally, i would delete the content in all the form fields in the first row and then have it prompt me if i want to delete that row or not.

Does that make sense?

Apologies for cross-posting; I don't want to ruffle any feathers, obviously, but do appreciate the help.

Thanks.
Reply With Quote
  #7  
Old 04-07-2013, 07:39 PM
macropod's Avatar
macropod macropod is offline Delete Current Row in protected Form Windows 7 64bit Delete Current Row in protected Form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I don't understand why you'd want to add a row, then delete another. Why not simply migrate the data from the existing lower rows and leave the lowest row ready for the latest data to be input?

There's no problem with cross-posting, per se. All that is asked for is that you provide the links so people don't waste their time covering ground that's been covered elsewhere - and so that anyone who might find your thread here while searching for a solution to a similar problem can find where/how it was resolved, if not here.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 04-07-2013, 07:43 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

Hmm. I don't know how the migrating of the lowest three rows would be accomplished though? I would need this to migrate up somehow that wouldn't involve people entering the lines of data all over again. That has been the stumbling block that I have been asked to fix.

That's why I figured that deleting the top row and adding a new row at the bottom would be optimal?

Thanks!
Reply With Quote
  #9  
Old 04-07-2013, 07:55 PM
macropod's Avatar
macropod macropod is offline Delete Current Row in protected Form Windows 7 64bit Delete Current Row in protected Form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

See attached. The document contains a macro named 'Migrate'. Run that and watch all the data on rows 3-5 move up one row and row 5 get cleared.
Attached Files
File Type: doc DataMigrate.doc (51.0 KB, 14 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 04-07-2013, 08:18 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

Now I see. Thanks!

I do like this solution but one of the issues is that the people who are going to be using this, aren't necessarily familiar with how to run macros, so I have to keep it really easy to use. Is easiest if the macro itself can prompt the user to delete or add to modify the rows.

Doug Robbins on the Microsoft forum just solved this for me:
http://answers.microsoft.com/en-us/o...=1365388494607

However, I am going to keep this solution and propose both and see what they think of it?

Thanks again!
Reply With Quote
  #11  
Old 04-07-2013, 08:29 PM
macropod's Avatar
macropod macropod is offline Delete Current Row in protected Form Windows 7 64bit Delete Current Row in protected Form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by joyfulincanada View Post
I do like this solution but one of the issues is that the people who are going to be using this, aren't necessarily familiar with how to run macros, so I have to keep it really easy to use. Is easiest if the macro itself can prompt the user to delete or add to modify the rows.
The only question becomes: how do you want to trigger the macro? One could, for example, trigger it as an 'on-entry' macro attached to the first formfield. See attached. An advantage of this approach is that, if the user makes the wrong choice, the effects are easily undone via the Undo button.
Attached Files
File Type: doc DataMigrate.doc (53.0 KB, 16 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 04-07-2013, 08:56 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

I see. I just tried this out and like the way this one works also.

Thanks! Will keep both solutions and present them tomorrow!
Reply With Quote
  #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
Reply

Thread Tools
Display Modes


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 10:33 AM.


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