Add new row in Table + new set of Form Fields

J

JohnLute

SLICK!!!

The only thing I was missing was setting the "Exit" dropdown in the dialog
of the last field.

This is great! Thanks so much!
 
J

JohnLute

DRAT!

I just realized that the form fields created in the new rows aren't
formatted. Can the code be revised to create new rows to contain the
formatted fields?

--
www.Marzetti.com


Jay Freedman said:
Hi John,

You have to "kickstart" the process:

- Create the table in the template. Include any header rows and then one
regular row.

- Insert a form field in each cell of that row.

- Open the Properties dialog of the form field in the last column (most
easily by double-clicking the field).

- Pull down the "Exit" dropdown in the dialog and choose AddRow as the exit
macro. Then click OK.

- Protect the template for forms. Save and close it.

- Use File > New and select the template to create a new document based on
the template.

When you exit that last form field in the existing row, the macro will run.
It will create a new row, fill it with form fields, and set the Exit macro
of the last new field to the same macro.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Thanks, Jay!

I've created a Macro named "AddRow" and included the code below
however, when I exit the field in the last cell of the row the macro
doesn't execute.

Again, I'm rather new to the world of Word macros and I can't see
where I've gone wrong. Any suggestions you might have would be
greatly appreciated.

Thanks!

Hi John,

It's easier to answer question 2 first -- yes, use Tools > Macro >
VBE (or the shortcut Alt+F11). You'll also need to create a module
to hold the code. Full instructions are at
http://www.gmayor.com/installing_macro.htm.

For question 1: No, Stephanie's code inserts only five form fields
in each new row. You could add another five segments of code to fill
the remaining five columns, but that would be tedious, not to
mention making the macro that much harder to update if your
requirements change in the future. I recommend the following
version, which figures out how many times to repeat the action by
asking how many columns the table has. [Note that this version will
generate an error if the table contains any merged or split cells. I
assume it's all uniform.]

Sub addrow()
Dim response As Integer
Dim myRow As Long
Dim myCount As Long
Dim colCount As Long
Dim colIndex As Long
Dim myNewField As String

response = MsgBox("Add new row?", vbQuestion + vbYesNo)
If response = vbYes Then
ActiveDocument.Unprotect

colCount = Selection.Tables(1).Columns.Count

Selection.InsertRowsBelow 1
Selection.Collapse (wdCollapseStart)
myRow = Selection.Information(wdStartOfRangeRowNumber)

For colIndex = 1 To colCount - 1
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Name = "text" & colIndex & "row" & myRow
.Enabled = True
End With
Selection.MoveRight Unit:=wdCell
Next colIndex

Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Name = "text" & colCount & "row" & myRow
.Enabled = True
.ExitMacro = "addrow"
End With
myNewField = "text1row" & myRow
ActiveDocument.Protect NoReset:=True, _
Type:=wdAllowOnlyFormFields
ActiveDocument.Range.FormFields(myNewField).Select
End If

End Sub

A couple of other comments:

- You may decide that the prompt "Add new row?" is unnecessary. If
so, remove the MsgBox line, the If statement that follows it, and
the End If at the end of the macro.

- The Dim statements at the start of the code are "optional" but
highly recommended; see
http://word.mvps.org/FAQs/MacrosVBA/DeclareVariables.htm.

- For a macro that might be used in other templates, there should be
some error-trapping. At a minimum, the macro should start by making
sure that the Selection is currently in a table, and not in a form
field elsewhere in the document (it shouldn't be, since this is an
exit macro, but you never know whether the next template obeys the
unwritten rules). The statements

If Not Selection.Information(wdWithInTable) Then
Exit Sub
End If

when placed right after the Dim statements will prevent such errors.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.


JohnLute wrote:
Hi, Stephanie.

I can't believe I found such an informative thread on my first
search! I have a couple questions as I'm entirely unfamiliar with
Word's macro functions (I'm more familiar with Access and I suppose
there are some similarities).

1. My table has 10 columns. Will this code still work?
2. How do I create this code in Word? I'm assuming it's Tools >
Macro
VBE.

Thanks so much!
 
J

Jay Freedman

Formatted in what way?
DRAT!

I just realized that the form fields created in the new rows aren't
formatted. Can the code be revised to create new rows to contain the
formatted fields?

Hi John,

You have to "kickstart" the process:

- Create the table in the template. Include any header rows and then
one regular row.

- Insert a form field in each cell of that row.

- Open the Properties dialog of the form field in the last column
(most easily by double-clicking the field).

- Pull down the "Exit" dropdown in the dialog and choose AddRow as
the exit macro. Then click OK.

- Protect the template for forms. Save and close it.

- Use File > New and select the template to create a new document
based on the template.

When you exit that last form field in the existing row, the macro
will run. It will create a new row, fill it with form fields, and
set the Exit macro of the last new field to the same macro.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

Thanks, Jay!

I've created a Macro named "AddRow" and included the code below
however, when I exit the field in the last cell of the row the macro
doesn't execute.

Again, I'm rather new to the world of Word macros and I can't see
where I've gone wrong. Any suggestions you might have would be
greatly appreciated.

Thanks!


Hi John,

It's easier to answer question 2 first -- yes, use Tools > Macro >
VBE (or the shortcut Alt+F11). You'll also need to create a module
to hold the code. Full instructions are at
http://www.gmayor.com/installing_macro.htm.

For question 1: No, Stephanie's code inserts only five form fields
in each new row. You could add another five segments of code to
fill the remaining five columns, but that would be tedious, not to
mention making the macro that much harder to update if your
requirements change in the future. I recommend the following
version, which figures out how many times to repeat the action by
asking how many columns the table has. [Note that this version will
generate an error if the table contains any merged or split cells.
I assume it's all uniform.]

Sub addrow()
Dim response As Integer
Dim myRow As Long
Dim myCount As Long
Dim colCount As Long
Dim colIndex As Long
Dim myNewField As String

response = MsgBox("Add new row?", vbQuestion + vbYesNo)
If response = vbYes Then
ActiveDocument.Unprotect

colCount = Selection.Tables(1).Columns.Count

Selection.InsertRowsBelow 1
Selection.Collapse (wdCollapseStart)
myRow = Selection.Information(wdStartOfRangeRowNumber)

For colIndex = 1 To colCount - 1
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Name = "text" & colIndex & "row" & myRow
.Enabled = True
End With
Selection.MoveRight Unit:=wdCell
Next colIndex

Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Name = "text" & colCount & "row" & myRow
.Enabled = True
.ExitMacro = "addrow"
End With
myNewField = "text1row" & myRow
ActiveDocument.Protect NoReset:=True, _
Type:=wdAllowOnlyFormFields
ActiveDocument.Range.FormFields(myNewField).Select
End If

End Sub

A couple of other comments:

- You may decide that the prompt "Add new row?" is unnecessary. If
so, remove the MsgBox line, the If statement that follows it, and
the End If at the end of the macro.

- The Dim statements at the start of the code are "optional" but
highly recommended; see
http://word.mvps.org/FAQs/MacrosVBA/DeclareVariables.htm.

- For a macro that might be used in other templates, there should
be some error-trapping. At a minimum, the macro should start by
making sure that the Selection is currently in a table, and not in
a form field elsewhere in the document (it shouldn't be, since
this is an exit macro, but you never know whether the next
template obeys the unwritten rules). The statements

If Not Selection.Information(wdWithInTable) Then
Exit Sub
End If

when placed right after the Dim statements will prevent such
errors.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.


JohnLute wrote:
Hi, Stephanie.

I can't believe I found such an informative thread on my first
search! I have a couple questions as I'm entirely unfamiliar with
Word's macro functions (I'm more familiar with Access and I
suppose there are some similarities).

1. My table has 10 columns. Will this code still work?
2. How do I create this code in Word? I'm assuming it's Tools >
Macro
VBE.

Thanks so much!
 
J

JohnLute

In the form field options I've formatted the types, max lengths and text
formats of the fields. When the new row is created the new fields contain
unformatted fields.
 
J

Jay Freedman

You can add that kind of specification at the point in the code where the
field's name and Enabled state are defined. For example, the following
extract (a modified section of the macro I posted before) says that the
first column will be "regular text" with a maximum of 12 characters and with
Bold turned on; all other fields except the one in the last column will be
"number" fields with "0.00" format and a max width of 4. You can make this
as simple or as complicated as you need...

For colIndex = 1 To colCount - 1
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Name = "text" & colIndex & "row" & myRow
.Enabled = True
If colIndex = 1 Then
.TextInput.EditType Type:=wdRegularText
.TextInput.Width = 12
.Range.Bold = True
Else
.TextInput.EditType Type:=wdNumberText, _
Format:="0.00"
.TextInput.Width = 4
End If
End With
Selection.MoveRight Unit:=wdCell
Next colIndex

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

JohnLute

Thanks, Jay. That makes sense now. This is all new to me so I'll have to
noodle with it.

One more thing that came up that I hope you might be so kind to address is
regarding the exit option of the form text field that runs the macro to
create a new row. How do I code the macro so that the new field that's
created will also have an exit option that executes the macro again for
additional rows to be created? This seems rather complex to me.
 
J

Jay Freedman

...How do I code the macro so that the
new field that's created will also have an exit option that executes
the macro again for additional rows to be created?

That's already baked into the macro. Look near the end for the line

.ExitMacro = "addrow"

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

JohnLute

Hi, Jay.

I continue to struggle. The following is my code. It's returning compile
errors that I've indicated with "< >"

The first regarding the format points to:
Can't make an assignment to a read-only property

Some properties can't accept assignments. This error has the following cause
and solution:

You tried to assign a value to a property that can't accept assignment.
In some cases, a property can accept assignment only at specific times. For
example, a property might accept assignments at design time, but not at run
time. Check the Help for the specific property to see when it can accept
assignments, if ever.

The second regarding the control variable points to:

For control variable already in use

When you nest For...Next loops, you must use different control variables in
each one. This error has the following cause and solution:

An inner For loop uses the same counter as an enclosing For loop.
Check nested loops for repetition. For example, if the outer loop uses For
Count = 1 To 25, the inner loops can't use Count as the control variables.

Could you translate? This is still very foreign to me.

One more thing - the .ExitMacro = "addrow" code doesn't seem to be working.
The relative field prompts for an "addrow" bu the next row/field doesn't.

GEEESH - sorry for all the trouble!

Sub AddRow()
'
' AddRow Macro
' Macro created 7/17/2006 by jlute
'
Dim response As Integer
Dim myRow As Long
Dim myCount As Long
Dim colCount As Long
Dim colIndex As Long
Dim myNewField As String

response = MsgBox("Add new row?", vbQuestion + vbYesNo)
If response = vbYes Then
ActiveDocument.Unprotect

colCount = Selection.Tables(1).Columns.Count

Selection.InsertRowsBelow 1
Selection.Collapse (wdCollapseStart)
myRow = Selection.Information(wdStartOfRangeRowNumber)

For colIndex = 1 To colCount - 1
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
..Name = "text" & colIndex & "row" & myRow
..Enabled = True
End With
Selection.MoveRight Unit:=wdCell
Next colIndex

Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
..Name = "text" & colCount & "row" & myRow
..Enabled = True
..ExitMacro = "addrow"
End With
myNewField = "text1row" & myRow
ActiveDocument.Protect NoReset:=True, _
Type:=wdAllowOnlyFormFields
ActiveDocument.Range.FormFields(myNewField).Select

For colIndex = 1 To colCount - 1
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
..Name = "text" & colIndex & "row" & myRow
..Enabled = True
If colIndex = 1 Then
..TextInput.EditType Type:=wdNumber
..TextInput.Width = 6
..TextInput<.Format => "######"

<For colIndex = 2 To> colCount - 2
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
..Name = "text" & colIndex & "row" & myRow
..Enabled = True
If colIndex = 1 Then
..TextInput.EditType Type:=wdNumber
..TextInput.Width = 10
..TextInput.Format = "###-####-###"

For colIndex = 3 To colCount - 3
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
..Name = "text" & colIndex & "row" & myRow
..Enabled = True
If colIndex = 1 Then
..TextInput.EditType Type:=wdRegularText
..TextInput.Width = Unlimited
..TextInput.Format = Uppercase

For colIndex = 4 To colCount - 4
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
..Name = "text" & colIndex & "row" & myRow
..Enabled = True
If colIndex = 1 Then
..TextInput.EditType Type:=wdRegularText
..TextInput.Width = 30
..TextInput.Format = Uppercase

For colIndex = 5 To colCount - 5
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
..Name = "text" & colIndex & "row" & myRow
..Enabled = True
If colIndex = 1 Then
..TextInput.EditType Type:=wdRegularText
..TextInput.Width = 2
..TextInput.Format = Uppercase

For colIndex = 6 To colCount - 6
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
..Name = "text" & colIndex & "row" & myRow
..Enabled = True
If colIndex = 1 Then
..TextInput.EditType Type:=wdRegularText
..TextInput.Width = 2
..TextInput.Format = Uppercase

For colIndex = 7 To colCount - 7
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
..Name = "text" & colIndex & "row" & myRow
..Enabled = True
If colIndex = 1 Then
..TextInput.EditType Type:=wdRegularText
..TextInput.Width = 17
..TextInput.Format = Uppercase

For colIndex = 8 To colCount - 8
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
..Name = "text" & colIndex & "row" & myRow
..Enabled = True
If colIndex = 1 Then
..TextInput.EditType Type:=wdNumber
..TextInput.Width = 7
..TextInput.Format = "#######"

For colIndex = 9 To colCount - 9
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
..Name = "text" & colIndex & "row" & myRow
..Enabled = True
If colIndex = 1 Then
..TextInput.EditType Type:=wdNumber
..TextInput.Width = 5
..TextInput.Format = "#####"

For colIndex = 10 To colCount - 10
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
..Name = "text" & colIndex & "row" & myRow
..Enabled = True
If colIndex = 1 Then
..TextInput.EditType Type:=wdNumber
..TextInput.Width = 5
..TextInput.Format = "#####"

End If
End Sub
 
G

Greg Maxey

I am "J" come late in this discussion I know and I haven't read the
entire thread just the topic. I worked with Jezeble a few months ago
on creating a macro to add a row with similiar formfields in a table.
Here is what we worked out:

Sub NewRow()
Dim pTable As Word.Table
Dim oRng1 As Word.Range
Dim oRng2 As Word.Range
Dim oRng3 As Word.Range
Dim oFormField As Word.FormField
Dim bCalcFlag As Boolean
Dim oRowID As Long
Dim i As Long
If MsgBox("Do you want to create a new row?", vbQuestion + vbYesNo,
"Create New Row") = vbYes Then
ActiveDocument.Unprotect
bCalcFlag = False
Set pTable = Selection.Tables(1)
Set oRng1 = pTable.Rows(pTable.Rows.Count).Range
Set oRng3 = oRng1.Duplicate
With oRng1
.Copy
.Collapse Direction:=wdCollapseEnd
.Paste
End With
Set oRng2 = pTable.Rows(pTable.Rows.Count).Range
For i = 1 To oRng1.FormFields.Count
oRowID = oRng1.FormFields.Count
Set oFormField = oRng1.FormFields(i)
With oFormField
If .Type = wdFieldFormTextInput Then
If Not bCalcFlag And .TextInput.Type = 5 Then
bCalcFlag = True
MsgBox "You must edit expressions in any new calculation
fields."
End If
End If
End With
oRng2.FormFields(i).Select
With Dialogs(wdDialogFormFieldOptions)
.Name = oRng3.FormFields(i).Name & "_" & oRowID
.Execute
End With
Next
If Not bCalcFlag Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End If
End Sub
 
J

JohnLute

Thanks, Greg. I gave your code a try and it returned a syntax error on this
line:

If MsgBox("Do you want to create a new row?", vbQuestion + vbYesNo,
 
G

Greg Maxey

That is due to text wrapping in this newsgroup. Make sure that
everything between IF and Then is on one line.

Also, one problem with any ADDROW macro is how to "Name" (bookmark) the
copied fields. I haven't come up with a great solution and the copied
names get longer and longer with each row added. However change:

oRowID = oRng1.Formfields.Count

to

oRowId = pTable.Rows.Count

which works a litte better.
 
J

Jay Freedman

Hi John,

I'm sorry, but your efforts are so far in the wrong direction that I don't
have the time to discuss the problems. I've taken the formatting you appear
to be trying to get, and made a version of the macro that works properly
here. Please try it, verify that it works for you, and study the code. When
you paste it into the VBA editor, put your cursor on various keywords and
press F1 to bring up the help about that topic. If there are specific bits
you don't understand, feel free to ask about them.

Sub AddRow()
'
' AddRow Macro
' Macro modified 7/19/2006 by Jay Freedman
'
Dim response As Integer
Dim myRow As Long
Dim myCount As Long
Dim colCount As Long
Dim colIndex As Long
Dim myNewField As String

response = MsgBox("Add new row?", vbQuestion + vbYesNo)
If response = vbYes Then
ActiveDocument.Unprotect

colCount = Selection.Tables(1).Columns.Count

Selection.InsertRowsBelow 1
Selection.Collapse (wdCollapseStart)
myRow = Selection.Information(wdStartOfRangeRowNumber)

' one loop that creates and formats fields in all
' except the last column
For colIndex = 1 To colCount - 1
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Name = "text" & colIndex & "row" & myRow
.Enabled = True
With .TextInput

' during each pass through the For loop,
' the variable colIndex will have exactly
' one of the values from 1 to 9
Select Case colIndex
Case 1
.EditType Type:=wdNumberText, _
Format:="######"
.Width = 6

Case 2
.EditType Type:=wdNumberText, _
Format:="###-####-###"
.Width = 10

Case 3
.EditType Type:=wdRegularText, _
Format:="Uppercase"
.Width = 0

Case 4
.EditType Type:=wdRegularText, _
Format:="Uppercase"
.Width = 30

Case 5, 6
' columns 5 and 6 have the same format
.EditType Type:=wdRegularText, _
Format:="Uppercase"
.Width = 2

Case 7
.EditType Type:=wdRegularText, _
Format:="Uppercase"
.Width = 17

Case 8
.EditType Type:=wdNumberText, _
Format:="#######"
.Width = 7

Case 9
.EditType Type:=wdNumberText, _
Format:="#####"
.Width = 5

Case Else
' do nothing
End Select
End With
End With
Selection.MoveRight Unit:=wdCell
Next colIndex ' end of the For loop

' now create and format the field in the last column,
' which needs an ExitMacro
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
.Name = "text" & colCount & "row" & myRow
.Enabled = True
.ExitMacro = "addrow"
With .TextInput
.EditType Type:=wdNumberText, _
Format:="#####"
.Width = 5
End With
End With
myNewField = "text1row" & myRow
ActiveDocument.Protect NoReset:=True, _
Type:=wdAllowOnlyFormFields
ActiveDocument.Range.FormFields(myNewField).Select
End If
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

JohnLute

Wow - there's certainly more than one way to do something!

This is working great however, I have a row directly below the row that
contains the field with the on exit property to execute the macro. The macro
is now adding a new row that contains the fields, etc. of the last row.

Is there a way to correct this or should I simply create another table to
house the data I need to enter into the last row?
 
J

JohnLute

LOL! No problem, Jay! My life's story should be titled "E for effort." As I
noted, this is rather new to me so I'm not surprised to see I've taken things
out into left field.

Thanks so much for your help. Greg has also provided a solution that I'm
experimenting with. I'm always amazed at what seems to be endless ways to do
something.

I truly appreciate your help. I'm in a pickle now as to which solution to use!
 
G

Greg Maxey

John,

With some work you could probably sort that out with code, but it would be
just as effective and far easier IMHO to use a second table as the last row.
 
J

JohnLute

I took that path of least resistance and created the second table. Everything
works like a champ! It makes the form VERY functional. I think I'll settle on
this solution but as always I'm amazed at the great help and suggestions
here! You guys are the BEST!

After running through this a few times the only negative thing I see is that
upon adding a new row the cursor doesn't move to the first field of the new
row but rather it stays in the field that contains the exit property. I can
see where this will frustrate users. Has anyone else commented about this?
 
G

Greg Maxey

John,

Never been brought up because I was never really happy with the field
(bookmark) naming problem and so never posted this as a solution. I see
your point.

Between the last two End If statements try adding:

pTable.Rows.Last.Cells(1).Range.Fields(1).Result.Select

Change "Cells(1)" to equate to the cell number in the row that has the first
formfield.
 
J

JohnLute

I don't see the naming problem as an issue with my particular form. It's a
rather simple form designed to communicate one row of data however, there are
times when multiple rows will be needed therefore, the code works fine for
this purpose.

I just added the code below and it works fine - big difference! Also, I
changed one of the text fields to a drop-down and was pleased that the addrow
code had no problems creating another drop-down to the new row. I was
anticipating some clash but it's fine!

I think I'm ready to fly now! Thanks again for your help! I appreciate your
coming in late! Stephanie got me down the runway and Jay got me in the air
and you've sent me to the moon :)

I'll say it again - this is a wonderful resource and you guys are GREAT! I
owe you a Coke!
 
G

Greg Maxey

JohnLute,

Good. Glad I could help. Perhaps I will try to refine this method a
bit more and post of my website after all. BTW, my significant partner
in the project was Jezebel not Jezeble. He (or perhaps she) came up
with the row copy part which eliminated a lot of the code.
 
R

Rich

I have successfully created an OnExit macro that creates a new row in the
table and adds a FormField to each cell. My additional desire is to set
certain FormFields to be unprotected. How can I do that from my macro? In
setting up the document protection, I was able to manually select certain
FormFields and create Exceptions (in the Protect Document panel) so that
those FormFields are editable while the document is protected, but I don't
know how to do the same thing programmatically.

Stephanie Krieger said:
Hi,

Sure -- you can use an On Exit macro for something much
like this. It won't read your tab character, but you can
use a message box --

[snip]
 

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