PKisielewski
11-01-2006, 02:03 PM
I am having a problem when I copy a particular row that is selected in a table to NOT clear out the form fields that are in that row. My situation is
that I have a button for users to select to add a new row. This row will be inserted below the row and I have it populating text and form fields. It works fine except that when I select the add rows button it clears the text that I have typed in the first row (it actually is creating a new form field that replaces the one that has text in it). I would like the form fields in Table 4 and Row 1 to retain their text and not be replaced. Am I leaving something out of the code? Any help would be appreciated. Thanks in advance.
Row Example:
Serial/Lot: [formfield
Product#:[formfield]
Expiration: [f f ]
Qty: [ff]
Private Sub cmd_add_rows_Click()
' If document is protected, Unprotect it.
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="new"
End If
ActiveDocument.Tables(4).Rows(1).Select
Selection.Copy
Selection.Paste
ActiveDocument.Tables(4).Rows(2).Select
Selection.TypeText Text:="Serial / Lot: "
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Product #: "
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Expiration: "
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Qty: "
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
' ReProtect the document.
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, Password:="new"
End Sub
that I have a button for users to select to add a new row. This row will be inserted below the row and I have it populating text and form fields. It works fine except that when I select the add rows button it clears the text that I have typed in the first row (it actually is creating a new form field that replaces the one that has text in it). I would like the form fields in Table 4 and Row 1 to retain their text and not be replaced. Am I leaving something out of the code? Any help would be appreciated. Thanks in advance.
Row Example:
Serial/Lot: [formfield
Product#:[formfield]
Expiration: [f f ]
Qty: [ff]
Private Sub cmd_add_rows_Click()
' If document is protected, Unprotect it.
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="new"
End If
ActiveDocument.Tables(4).Rows(1).Select
Selection.Copy
Selection.Paste
ActiveDocument.Tables(4).Rows(2).Select
Selection.TypeText Text:="Serial / Lot: "
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Product #: "
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Expiration: "
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Qty: "
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
' ReProtect the document.
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, Password:="new"
End Sub