Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 09-09-2014, 11:54 AM
IanMC IanMC is offline Delete Rows in Protected Table with Form Fields Windows Vista Delete Rows in Protected Table with Form Fields Office 2013
Novice
 
Join Date: Sep 2014
Posts: 6
IanMC is on a distinguished road
Default

Hi Paul



Thank you for your prompt response. It was the most last piece of coding posted by yourself (04/26/2013), I selected this one as I will always need the top and bottom rows to show. Initially I tried to trigger the deletion from the detail contained in the second row (headed up purchase amount), each of these fields has been bookmarked (e.g. LA1 - LA10) however that seemed to be extremely complicated, hence trying to replicate this section. But even this seems to be beyond me!

I've attached a duplicate of the table in question, any light you can shed would be most welcome!
Attached Files
File Type: doc Macro Template.doc (54.0 KB, 14 views)
Reply With Quote
  #17  
Old 09-09-2014, 09:38 PM
macropod's Avatar
macropod macropod is offline Delete Rows in Protected Table with Form Fields Windows 7 64bit Delete Rows in Protected Table with Form Fields Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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 macro to which you refer requires all formfields on a row to be empty before a deletion will occur. Your document, however, always has content in the formfields in columns 3-5. Hence no row will ever be deleted. Since your 'controlling' field appears to be the first one on each row, you might try:
Code:
Sub DeleteEmptyRows()
'Delete empty rows in the table
Application.ScreenUpdating = False
Dim StrPwd As String, i As Long
StrPwd = ""
With ActiveDocument
  If .ProtectionType = wdAllowOnlyFormFields Then .Unprotect Password:=StrPwd
  With .Tables(1)
    For i = .Rows.Count - 1 To 2 Step -1
      With .Rows(i)
        If Trim(.Range.FormFields(1).Result) = "" Then .Delete
      End With
    Next
  End With
  .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=StrPwd
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #18  
Old 09-10-2014, 02:55 AM
IanMC IanMC is offline Delete Rows in Protected Table with Form Fields Windows Vista Delete Rows in Protected Table with Form Fields Office 2013
Novice
 
Join Date: Sep 2014
Posts: 6
IanMC is on a distinguished road
Default

Hi Paul,

Thank you for that - that's spot on and works perfectly when I run it . Is there anything that can be added to it which would allow it to automatically run when the user leaves the table?

If I want to modify the code across other tables (using the same logic i.e. the formfield is blank in column 3) which sections would need updating, I understand the table reference, but I can't figure out the rest
Reply With Quote
  #19  
Old 09-10-2014, 03:23 AM
macropod's Avatar
macropod macropod is offline Delete Rows in Protected Table with Form Fields Windows 7 64bit Delete Rows in Protected Table with Form Fields Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

To automate the process, you could use a Selection_Change macro, but that's a lot of work to implement. A simpler approach would be to have another formfield, say a checkbox formfield, in the second cell on the last row that, when clicked, triggers the macro. You do that by selecting the macro from the formfield's 'on entry' property. To use the same macro on multiple tables, you could then simply change:
With .Tables(1)
to:
With Selection.Tables(1)
and, if you want to delete the formfield that triggered the macro as well, insert:
Selection.FormFields(1).Delete
before:
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=StrPwd

PS: I note you're using a formfield to tally the column-2 values. The problem with this approach is that (a) you're using bookmarks that may get deleted when the referenced rows get deleted; (b) there's nothing in your code to cause the tally to update; and (c) calculation formfields taking input from other formfields are dodgy. To resolve (a) and (c), replace the calculation formfield with a formula field, coded as:{=SUM(ABOVE) \# £0.00 }
For (b), check each of the other formfields' 'calculate on exit' property.

Note: The field brace pairs (i.e. '{ }') for the above example are created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #20  
Old 09-10-2014, 05:51 AM
IanMC IanMC is offline Delete Rows in Protected Table with Form Fields Windows Vista Delete Rows in Protected Table with Form Fields Office 2013
Novice
 
Join Date: Sep 2014
Posts: 6
IanMC is on a distinguished road
Default

Hi Paul,

Thank you for the additional guidance re: adding values - will amend accordingly.

I'm struggling to understand the multiple tables piece - how will the code know which tables it applies to?
Reply With Quote
  #21  
Old 09-10-2014, 08:56 AM
macropod's Avatar
macropod macropod is offline Delete Rows in Protected Table with Form Fields Windows 7 64bit Delete Rows in Protected Table with Form Fields Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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 IanMC View Post
I'm struggling to understand the multiple tables piece - how will the code know which tables it applies to?
It 'knows' that from the use of 'Selection.Tables(1)'. Since the formfield the macro is attached to is a Selection, that tells Word to use the first table in the selected range, rather than the first table in the document.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #22  
Old 09-11-2014, 12:52 AM
IanMC IanMC is offline Delete Rows in Protected Table with Form Fields Windows Vista Delete Rows in Protected Table with Form Fields Office 2013
Novice
 
Join Date: Sep 2014
Posts: 6
IanMC is on a distinguished road
Default

Hello,

Apologies for the simple/ daft questions; I'm new to this so it's all a very steep learning curve!

I've tried altering the code so that the same happens to table 18 (with the formfield in the 3rd column), I changed the table reference to correspond, but no deletion occurs. There is a Reference field in column 2, but as this is not a formfield I'm thinking that this won't be impacting on it. Is there a bit of the code which needs updating to reflect that it's the 3rd column?
Reply With Quote
  #23  
Old 09-11-2014, 01:28 AM
macropod's Avatar
macropod macropod is offline Delete Rows in Protected Table with Form Fields Windows 7 64bit Delete Rows in Protected Table with Form Fields Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Using the latest code revisions I provided you should not make any changes to the table referencing. It will work as is with whatever the current table is, be that table 1 or 100. Even working with column 3 instead of column 2 doesn't require a code change unless there are formfields in columns 1 or 2. If so, a different macro would be required - basically the existing one with '1' in .FormFields(1) changed to whichever the correct formfield # is on the rows concerned.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #24  
Old 09-11-2014, 12:47 PM
IanMC IanMC is offline Delete Rows in Protected Table with Form Fields Windows Vista Delete Rows in Protected Table with Form Fields Office 2013
Novice
 
Join Date: Sep 2014
Posts: 6
IanMC is on a distinguished road
Default

Hi Paul,

Thank you so much - I was trying to be too clever for my own good (I know better now)

It's working perfectly, even better than I have anticipated. Really appreciate you're help with this

Ian
Reply With Quote
Reply

Tags
delete row, form fields, protected form



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Rows in Protected Table with Form Fields Text Form Fields - Filling the table cell simville02 Word Tables 1 01-31-2013 11:12 PM
Using macro to add variable number of rows to a protected word table Julia Word Tables 1 01-09-2013 06:04 AM
Delete Rows in Protected Table with Form Fields Delete all rows but the last. elky1967 Word VBA 14 09-21-2012 05:27 AM
Adding table lines to protected form razberri Word Tables 2 10-27-2010 05:58 PM
Editing Password protected form fields in Word 2007 tamilan Word 2 02-16-2010 09:45 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:40 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