Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #19  
Old 11-12-2013, 02:27 PM
macropod's Avatar
macropod macropod is offline Tables with form fields Windows 7 32bit Tables with form fields Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,355
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

Try your document with the following code:
Code:
Option Explicit
Dim bLastCell As Boolean
 
Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
With Selection
  If .Information(wdWithInTable) = True Then
    With ActiveDocument.Tables(2).Range
    If Selection.Cells(1).RowIndex = .Cells(.Cells.Count).RowIndex Then
      If Selection.Cells(1).ColumnIndex = .Cells(.Cells.Count).ColumnIndex Then
        bLastCell = True
      End If
    End If
    End With
  End If
End With
End Sub
 
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Application.ScreenUpdating = False
Dim CCtrl As ContentControl, Prot As Long, Pwd As String, i As Long, j As Long
If bLastCell = True Then
  If Selection.Tables(1).Range = ActiveDocument.Tables(2).Range Then
    If MsgBox("Add new row?", vbQuestion + vbYesNo) = vbYes Then
      If ActiveDocument.ProtectionType <> wdNoProtection Then
        Pwd = "" 'Insert password here
        Prot = ActiveDocument.ProtectionType
        ActiveDocument.Unprotect Password:=Pwd
      End If
      ContentControl.Range.Select
      Selection.SplitTable
      ContentControl.Range.Select
      Selection.Tables(1).Rows.Last.Range.Characters.Last.Next.InsertBefore vbCr
      With Selection.Tables(1).Rows
        .Last.Range.Copy
        .Last.Range.Next.Paste
        For Each CCtrl In .Last.Range.ContentControls
          With CCtrl
            If .Type = wdContentControlCheckBox Then .Checked = False
            If .Type = wdContentControlRichText Or .Type = wdContentControlText Then .Range.Text = ""
            If .Type = wdContentControlDropdownList Then .DropdownListEntries(1).Select
            If .Type = wdContentControlComboBox Then .DropdownListEntries(1).Select
            If .Type = wdContentControlDate Then .Range.Text = ""
            .LockContentControl = True
          End With
        Next
        .First.Range.Characters.First.Previous.Delete
      End With
      ActiveDocument.Protect Type:=Prot, Password:=Pwd
    End If
  End If
  bLastCell = False
End If
Application.ScreenUpdating = True
End Sub
The principal issues that had to be dealt with here are:
1. you're working with the second table in the document, whereas the example had only one; and
2. your table has vertically-split cells (which makes it impossible to work with a row designation.

PS: I note you now have a mix of content controls and formfields in your document. You really should use one or the other - they are not designed to work together.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tables with form fields Form Fields - Create blank form text field with if statement? LAssist2011 Word 5 12-14-2011 03:02 PM
Tables with form fields Form Fields jwm1346 Word 1 11-17-2011 03:08 AM
Tables with form fields How to make two independent columns not using fields and tables Macieto Word 4 09-14-2011 04:53 AM
Tables with form fields Tab through fields on a form. Keep on Ticking Word 1 06-23-2011 03:29 AM
Form Fields questions Word 0 04-27-2009 10:48 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:34 AM.


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