Create a form which automatically adds fields as needed

R

Robert S.

Hi,

I am having difficulties implementing this in Word 2002 using VBA. Any
advice, solutions, point in the right direction would be very much
appreciated.

I have a form created in Word 2002, and some of the questions I do not
know beforehand how many fields I will need. The user can enter one
entry, or 50 entrys. Rather than having a whole page of empty fields
for users who just want to enter in one, I would like to make the
program add a new line of fields if the preceding line of fields was
completed.

How would I go about doing this? I know I should run an exit macro on
the last field, but how do I get it to create a new line of fields,
and have the macro work on the last field of the new line?

I'm really stumped on this!
 
R

Robert S.

Please disregard this post. I reposted this message in the
UserForms group: microsoft.public.word.vba.userforms
 
G

Guest

Probably your best bet is to use Excel... you can make
this look like a word documents... but you will have much
more control over the placement of fields and entries by
using the Cell references...

I am not sure how you would do this using word.
 
R

Robert S.

Below is the code I got from Doug Robbins - Word MVP
regarding my problem. The code works, but it adds the
formfields to the first table in the Word Document. How do
I modify this so that it adds the formfields to the table
I want?

==============
Sub addrow()
'
' Macro created 02/02/03 by Doug Robbins ([email protected])
' 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.Tables
(1).Rows.Count, ActiveDocument.Tables
(1).Columns.Count).Range.FormFields(1).ExitMacro = "addrow"
ActiveDocument.Tables(1).Cell(ActiveDocument.Tables
(1).Rows.Count, 1).Range.FormFields(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields,
NoReset:=True

End Sub

====================
 
D

Doug Robbins - Word MVP

Hi Robert,

Each formfield added by that procedure will have the default Text# bookmark
assigned to it.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
R

Robert S.

Hi Doug,

The procedure only added the bookmark to the first field
in the new row and not the others. However, I need more
control than the standard Text# bookmark, since I have
multiple tables it would be difficult to ascertain where
one table left off, and another began. So if I can the
fields based on the table it came from, that would be the
perfet solution.

Thanks,

Robert
 

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