How can I....

F

FredEp57

I have some code (attached at the end of this question). However, I cannot
figure out how to keep this from adding a row if I use the mouse to click
into another form field.

Any help would be appreicated.

Attached code
===========================
Sub add2()
' Copying the last row in its entirety to a newly created row is
trivial:
' however, getting the correct parts and pieces are more complicated

Dim rownum, colnum As Integer
Dim mRow, mCol, i, j As Integer
Dim mVar As String

' First check that you are using a document not at template.
If ActiveDocument.Name = ActiveDocument.AttachedTemplate Then
MsgBox "You're trying to write to the template"
End
End If

If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect 'Password:="pass",
End If

mRow = Selection.Tables(1).Rows.Count

With Selection.Tables(1)
.Rows(.Rows.Count).Range.Copy
.Rows(.Rows.Count).Range.Paste
End With

For j = 1 To Selection.Tables(1).Columns.Count
Select Case Selection.Tables(1).Cell(i, j).Range.FormFields(1).Type
Case wdFieldFormTextInput
Selection.Tables(1).Cell(i, j).Range.FormFields(1).Result = ""
Case wdFieldFormDropDown

Case wdFieldFormCheckBox

End Select
Next j

iRows = Selection.Tables(1).Rows.Count
iCols = Selection.Tables(1).Columns.Count
iUpOneRow = iRows - 1

Selection.Tables(1).Cell(iUpOneRow, iCols).Range.FormFields(1).ExitMacro
= ""
Selection.Tables(1).Cell(iRows, iCols).Range.FormFields(1).ExitMacro =
"add2"
Selection.Tables(1).Cell(Selection.Tables(1).Rows.Count,
1).Range.FormFields(1).Select

ActiveDocument.Protect NoReset:=True, Type:=wdAllowOnlyFormFields
'Password:="pass",


End Sub
=======================================
 
C

Chuck

You've got an ExitMacro = add2() set to run when you exit a form field so
whenever you exit that field, the macro will run again. You'll need either
create a different exit macro or add some code to check whether another row
needs to be added.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top