I have a word table with 3 columns and 5 rows. The first 2 cells of each row contains text form fields and the 3rd cell of each row has a dropdown form field. I created a a VB procedure called Addrow and entered this event to on-Exit of the last cell
#3 (dropdown field) of row 5. When a user tabs off this last cell, a pop-up asks if they would like to add a new row to the table. It then creates the new row. My problem is, I need to add the Addrow event to the last cell (#3) of
the newly created row. I cant seem to find the sytax to get it right. See coode here:
Sub addrow()
Dim oTable As Table
Dim Response As String
Dim CurRow As Long
Dim i As Long
Dim fCount As Long
Dim sPassword As String
Set oTable = ActiveDocument.Tables(1)
sPassword = "" 'Define the password used to protect the form (if any)
Response = MsgBox("Add new row?", vbQuestion + vbYesNo)
If Response = vbYes Then
ActiveDocument.Unprotect 'Password:="sPassword" 'Unprotect document
Selection.InsertRowsBelow 1 'Add a row to the bottom of the table
Selection.Collapse (wdCollapseStart) 'Put the cursor in the first cell of the new row
CurRow = Selection.Information(wdStartOfRangeRowNumber) 'Read the number of the new row
For i = 1 To oTable.Columns.count
oTable.Cell(CurRow, i).Select 'Select the next cell for processing
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput 'And add a form field
'If i = 3 Then
'.ExitMacro = "addrow" 'add this macro to the cell in column 3
'fCount = ActiveDocument.Range.FormFields.count
Next i
With ActiveDocument
'Password:="sPassword",
.Protect NoReset:=True, _
Type:=wdAllowOnlyFormFields 'Reprotect the form
'.Range.FormFields("col1row" & CurRow).Select 'Select the first field in the new row
End With
End If
End Sub