PDA

View Full Version : Solved: Problem with FormFields in a Table



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

ctengelen
11-02-2006, 08:24 AM
:hi: Hi There,
Would it not be better if you would AutoText to insert your new rows? This way the FormFields are already set and will not get deleted in the process.

I tried to use the copy and past before and utterly failed in my forms.
I now set up my table rows with all the FormFields etc - copy it into AutoText (must be attached to the template) and all is working fine.

PKisielewski
11-02-2006, 08:36 AM
Please explain - I am unfamiliar with using AutoText. The formfields in Tables(4).Rows(1) are inputted by the user. The only reason that I wanted to add rows is that sometimes the user does not need more than one. In the original form I had 3 static rows but thought that it would be nice if the user needs more than one they can select a button to open up additional rows. Also, it would save space when they print out the form to not have the extra rows that are not needed.
So if I use AutoText will it retain the information that the user types in?
Let me know and thanks.

ctengelen
11-02-2006, 09:37 AM
I have attached a little document that will help explain the AutoText - I hope it makes sense to you.

Trudy:)

PKisielewski
11-02-2006, 02:06 PM
Thanks so much for showing me how to do Autotext but I fiqured out my problem with using the copy feature. My problem was in the password statement. It was resetting the formfields. I changed the NoReset to true and it worked. See the following :
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="new"

I will keep the AutoText in mind - it is a good feature. In my code I also have a delete button to delete the added row. I am not sure if the AutoText would work for the delete. There are still some bugs for instance I don't want them to get crazy and start deleting too many rows. Anyway, that is my next task. Thanks again for your help.:bow: