Dr@g0nfly
03-06-2007, 01:59 PM
Hi I have a protected form in Word 2000. I have inserted text fields into a table to allow the user to type the account numbers that will be affected by the form's contents into the document. I have only supplied two rows in the table but there is the possibility that there could be more needed. I add a command button with the following code attached to it:
Sub AddRow()
ActiveDocument.Unprotect
ActiveDocument.Tables(3).Rows.Add
Selection.Collapse Direction:=wdCollapseStart
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub
This works great but I found during a trial that the user was able to type continuously in the new text fields whereas I had set the maximum length to 10 in the previous two rows, as well as the text type to "number". I need to restrict the fields but since they are being adding dynamically at the request of the user, I'm not sure how to set those properties... is there a way to set the maximum length and text field type using VBA code? I was hoping to add it to the code above so that when the fields are inserted, the code also tells the program which specific ones. I was thinking perhaps autotext might be a good place to start but the autotext refers to the Normaltemplate????
Sub AddRow()
ActiveDocument.Unprotect
ActiveDocument.Tables(3).Rows.Add
Selection.Collapse Direction:=wdCollapseStart
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub
This works great but I found during a trial that the user was able to type continuously in the new text fields whereas I had set the maximum length to 10 in the previous two rows, as well as the text type to "number". I need to restrict the fields but since they are being adding dynamically at the request of the user, I'm not sure how to set those properties... is there a way to set the maximum length and text field type using VBA code? I was hoping to add it to the code above so that when the fields are inserted, the code also tells the program which specific ones. I was thinking perhaps autotext might be a good place to start but the autotext refers to the Normaltemplate????