Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2005

Tip: Looking for answers? Try searching our database.

How can I....

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
FredEp57 - 11 Jul 2005 01:31 GMT
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
=======================================
Chuck - 11 Jul 2005 11:07 GMT
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.

> 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
[quoted text clipped - 57 lines]
> End Sub
> =======================================
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.