Reply
 
Thread Tools Display Modes
  #1   Report Post  
Stikfa
 
Posts: n/a
Default Inserting a row with a form field.

I have a table setup withtwo columns to insert a new row when you tab through
the las column. Using this code:
With Selection
If .Information(wdWithInTable) Then
.Tables(1).Rows.Last.Select
.InsertRowsBelow 1
End If
End With

And all is good, except that I would like to create the new row with a 'Text
Form Field' in each column.

The last row of my table already has the form fields. So is it possible to,
when inserting the new row, to have it also insert the form fields or maybe
have it copy the filds from the previouse row?

thx

  #2   Report Post  
Doug Robbins
 
Posts: n/a
Default

The following macro does what you want. Watch out for the linebreaks
inserted by the mail program.



Sub addrow()

' Macro created 02/02/03 by Doug Robbins

' To add a new row to a table containing formfields in every column

' automatically on exit from the last cell in the present last row of the
table

Dim rownum As Integer, i As Integer

ActiveDocument.Unprotect

ActiveDocument.Tables(1).Rows.Add

rownum = ActiveDocument.Tables(1).Rows.Count

For i = 1 To ActiveDocument.Tables(1).Columns.Count

ActiveDocument.FormFields.Add
Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
Type:=wdFieldFormTextInput

Next i

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
ActiveDocument.Tables(1).Columns.Count).Range.Form Fields(1).ExitMacro =
"addrow"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.FormFields(1).Select

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True



End Sub

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
"Stikfa" wrote in message
...
I have a table setup withtwo columns to insert a new row when you tab
through
the las column. Using this code:
With Selection
If .Information(wdWithInTable) Then
.Tables(1).Rows.Last.Select
.InsertRowsBelow 1
End If
End With

And all is good, except that I would like to create the new row with a
'Text
Form Field' in each column.

The last row of my table already has the form fields. So is it possible
to,
when inserting the new row, to have it also insert the form fields or
maybe
have it copy the filds from the previouse row?

thx



  #3   Report Post  
Jay Freedman
 
Posts: n/a
Default

Stikfa wrote:
I have a table setup withtwo columns to insert a new row when you tab
through the las column. Using this code:
With Selection
If .Information(wdWithInTable) Then
.Tables(1).Rows.Last.Select
.InsertRowsBelow 1
End If
End With

And all is good, except that I would like to create the new row with
a 'Text Form Field' in each column.

The last row of my table already has the form fields. So is it
possible to, when inserting the new row, to have it also insert the
form fields or maybe have it copy the filds from the previouse row?

thx


Hi Stikfa,

The same macro that adds the row can also insert new fields in it. The
following code is a bit more complicated than what you showed, but it has
two main advantages: (1) it doesn't move the Selection, which corresponds to
the insertion point in the document, and (2) it will insert the right number
of fields, regardless of how many columns your table has.

Dim myTable As Table
Dim myRow As Row
Dim ColNum As Long

If Not Selection.Information(wdWithInTable) Then
Exit Sub ' no table; don't do any more
End If

' make an onject that represents the table
Set myTable = Selection.Tables(1)

' add a row to the bottom of the table
' and make an object that represents the row
Set myRow = myTable.Rows.Add

' use a loop to insert a form field into
' each cell in the new row
For ColNum = 1 To myTable.Columns.Count
ActiveDocument.FormFields.Add _
Range:=myRow.Cells(ColNum).Range, _
Type:=wdFieldFormTextInput
Next ColNum

' clean up
Set myRow = Nothing
Set myTable = Nothing

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Enter data in 1 text form field & have multiple locations fill Lee Microsoft Word Help 1 March 16th 05 10:56 PM
How do I make "tab" go from form field to form field? DLS Microsoft Word Help 2 February 16th 05 07:44 PM
Form Field (defining and associating a bookmark with it) Judi Microsoft Word Help 2 February 11th 05 09:53 PM
Text Form Field Ref in Footer Won't Update on Screen StarWine Microsoft Word Help 3 December 6th 04 06:17 PM
Form Field Automation Mitch Microsoft Word Help 2 November 29th 04 07:29 PM


All times are GMT +1. The time now is 05:17 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"