forms and tables

F

FredEp57

Not sure if the first one got through so I am asking again.

I want to have a table in my form. The table has text fields in each cell.
I need to have the table grow dynamically and have the text field in each new
row/cell.

Can this be done? Or am I approaching this the wrong way?

Thanks
F
 
J

Jezebel

Yes, you're approaching this the wrong way. Not sure what the right way is
without knowing what you really need to end up with, but Word forms can't
spawn new fields dynamically, in a table or anywhere else.
 
D

Doug Robbins

' 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.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


--
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
 
D

Doug Robbins

It got through and I now realise that I posted an answer to it yesterday.

--
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
 
F

FredEp57

Doug,

Thanks. However my skills at VBA are very poor. Can I just cut and paste
this into the VBA editor? I tried and get compilation errors after the
ActiveDocument.FormFields.Add line.

Let me now how to put this in the document.

F
 
F

FredEp57

Doug,

FInally got this to "work". However, I have a couple of problems.
1 - can you explain each line (what it does and/or is doing) please?
2 - I have a lot of different tables so need to access the first and third.
Changing (globally) from (1) to (3) for the third causes an error.
3 - when I use the code on exit, the next row does not add any fields. Am I
missing something?

Thanks again for you invaluable help.

F
 
D

Doug Robbins

Replace

ActiveDocument.Tables(1)

with

Selection.Tables(1)

wherever the former occurs.

The lines of code a pretty self explanatory.

The only other thing that I would add is that the macro needs to be named
Sub AddRow(). That was omitted from the code as pasted.

--
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
 
F

FredEp57

Doug,

Again, thanks. I am trying to improve my skills and your tips have helped
immensely.

I would ask one more part. I have a table I built. Some of the cells have
textboxes and some have drop downs. How can I make a new row with the same
things in it?

Example, if I have a table with three cells and two have text and one has a
drop down with 5 choices. I need to make an exact copy of the upper row into
this new row. I can't figure out how to get the choices and drop down into
the table.

I can't find much on explaining the different keywords.

Again, Thanks much!!!
F
 
D

Doug Robbins

It's all there in the Visual Basic Help file.

e.g.

Returns a DropDown object that represents a drop-down form field. Read-only.

Remarks
If the DropDown property is applied to a FormField object that isn't a
drop-down form field, the property won't fail, but the Valid property for
the returned object will be False.

Example
This example displays the text of the item selected in the drop-down form
field named "Colors."

Dim ffDrop As FormField

Set ffDrop = ActiveDocument.FormFields("Colors").DropDown

MsgBox ffDrop.ListEntries(ffDrop.Value).Name
This example adds "Seattle" to the drop-down form field named "Places" in
Form.doc.

With Documents("Form.doc").FormFields("Places") _
.DropDown.ListEntries
.Add Name:="Seattle"
End With

--
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
 
F

FredEp57

Doug,

Thanks for this. However, now I get a very strange result.

I changed all the occurances per your instructions below. Now, however, for
some reason I get a dropdown field ALONG with the text input field in my
form. Can you explain this?

Thanks
F
 
D

Doug Robbins

Show us the final code.

--
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
 

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