reading formfields in a table

N

Nick Calladine

Can some one provide me the best syntax or method to read a single formfield
which is in a cell of a table

Each cell of the formfield is either a textinput field or dropdownbox.

I used the following code to step through each cell which i wish to read for
validation purposed

For ColumnNumber = 1 To 5
'Select Cell
ActiveDocument.Tables(1).Cell(RowNumber + 1, ColumnNumber).Range.Select
'Select Data In Cell
Selection.MoveLeft unit:=wdCharacter, Count:=1

<read / test data here>


Next ColumnNumber


Is this a bad way to do it.. i am better reading the cells data and then
figuring it out if its a form field and then act upon the type.

The formfields are not bookmaked as the user can addiontal rows to the
table.. is just a way of getting input and protecting the form.

Many thanks

Yours stupidly
 
G

Greg Maxey

Nick,

To be honest I don't see how you do much of anything with your code. You
say you "step through each cell." What is RowNumber? How does RowNumber 1
become RowNumber 2?

Anyway, if each cell in the table contains either a single text field or
dropdown, then you might try:

Sub ScratchMacro()
Dim oCell As Cell
For Each oCell In ActiveDocument.Tables(1).Range.Cells
MsgBox oCell.Range.FormFields(1).Result
Next
End Sub
 
N

Nick Calladine

Sorry Greg if it wasnt too clear

Still learning vba and get more involved with a simple project which is
getting more complex.

Sorry whats i was trying to do it..

I have a table which has none constant rows
Its has about 14 tables cells per row

I basically want to

read the first five cells of each row
i then need to get the data from the cell (without the word cell info)
then test if this if it was a null field or where i was expecting to find
data.
if the data is invalid then go to each cell and put "invalid" in to each of
the text formfield enteries

if data is valid then do some calculation and write to other cells

and then go through the to the next row to the end of the first table

hopefully that make it clearer

so i looking to read an text formfield, validate if true do an caculation ;
if false then write information back in to the text formfield within the
cell

i understand than i need to loop through the table / each valid row and i
know the data lies in the first 5 colums.

what i dont know is how to read the textformfield - validate it and then
write back the formfield not the cell

hope thats makes thing a bit more sensicle..

regards

Nick
 
G

Greg Maxey

Nick,

You are still not very clear. For example, what does this mean?

<"I have a table which has none constant rows"

and this
Its has about 14 tables cells per row

Do you mean "nine" rows and 14 cells or columns per row?

Again this is just a simplistic example, but if you want to look at the
result of a single formfield in a table cell, compare it to something and
then change it based on that comparison you could use something like:

Sub ScratchMacro()
Dim oCell As Cell
For Each oCell In ActiveDocument.Tables(1).Range.Cells
If oCell.Range.FormFields(1).Result <> "Greg" Then
oCell.Range.FormFields(1).Result = "Greg"
End If
Next
End Sub
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
 

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