S
spunkymuffmonkey
Firstly, thank you for reading this post and looking at my problem.
I am currently developing a protected form for users to complete that
contains several separated tables within it.
One of the tables is used to record all children in the household, as most
households do not have more than 4 children I have preset the table to
contain 5 rows (one row is the header), but there is the possibility that
more than 4 children will need to be recorded in this table.
Therefore, I have used the advice and tips provided in other threads and
included an exit macro for the last field in the bottom row which will allow
users to add a new row.
My problem is that I would like to configure the on exit macro for the last
field in the new row so that the process can repeat itself as often as is
required by the user, but also clear the on exit macro for the previous row.
The code I have pasted below changes the exit macro for the last field in
the table at the very bottom of the document, not the last field in the
current table and I cannot work out how to change the code it to cater for
me. Do I need to go down the route of creating a name for the new fields and
using the name in the Macro and if so is this something somebody can
illuminate me regarding.
Any advice and suggestions will be greatly appreciated.
Thanks again.
Code:
Sub addrow()
response = MsgBox("Add new row?", vbQuestion + vbYesNo)
If response = vbYes Then
ActiveDocument.Unprotect Password:=""
Selection.InsertRowsBelow 1
Selection.Collapse (wdCollapseStart)
myRow = Selection.Information(wdStartOfRangeRowNumber)
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Enabled = True
End With
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Enabled = True
End With
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Enabled = True
End With
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Enabled = True
.ExitMacro = "addrow"
End With
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Enabled = True
Selection.MoveLeft Unit:=wdCell
Selection.MoveRight Unit:=wdCell
End With
ActiveDocument.Protect NoReset:=True, Password:="",
Type:=wdAllowOnlyFormFields
End If
End Sub
I am currently developing a protected form for users to complete that
contains several separated tables within it.
One of the tables is used to record all children in the household, as most
households do not have more than 4 children I have preset the table to
contain 5 rows (one row is the header), but there is the possibility that
more than 4 children will need to be recorded in this table.
Therefore, I have used the advice and tips provided in other threads and
included an exit macro for the last field in the bottom row which will allow
users to add a new row.
My problem is that I would like to configure the on exit macro for the last
field in the new row so that the process can repeat itself as often as is
required by the user, but also clear the on exit macro for the previous row.
The code I have pasted below changes the exit macro for the last field in
the table at the very bottom of the document, not the last field in the
current table and I cannot work out how to change the code it to cater for
me. Do I need to go down the route of creating a name for the new fields and
using the name in the Macro and if so is this something somebody can
illuminate me regarding.
Any advice and suggestions will be greatly appreciated.
Thanks again.
Code:
Sub addrow()
response = MsgBox("Add new row?", vbQuestion + vbYesNo)
If response = vbYes Then
ActiveDocument.Unprotect Password:=""
Selection.InsertRowsBelow 1
Selection.Collapse (wdCollapseStart)
myRow = Selection.Information(wdStartOfRangeRowNumber)
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Enabled = True
End With
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Enabled = True
End With
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Enabled = True
End With
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Enabled = True
.ExitMacro = "addrow"
End With
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Enabled = True
Selection.MoveLeft Unit:=wdCell
Selection.MoveRight Unit:=wdCell
End With
ActiveDocument.Protect NoReset:=True, Password:="",
Type:=wdAllowOnlyFormFields
End If
End Sub