Disable remaining formfields in the same row of a table.

S

Stuart Peters

Based upon a checkbox value in the form fields I am trying to disable or
enable the remaining formfields in the table row.
I believe the following code should work. but I am gettting a run-time error
'5991' on the for each statement that says 'I cannot access individual rows
in this collection because the table has vertically merged cells'

Sub EnableActionFields()
' Enable or Disable the Actions formfields
Dim ffname As String
Dim ActField As FormField
ffname = Selection.FormFields(1).Name
For Each ActField In ActiveDocument.FormFields(ffname).Range.Rows(1)
If ActiveDocument.FormFields(ffname).CheckBox.Value = True Then
'Field checked - No action required
ActField.Enabled = False 'Already have info disable this action
Else
'Field Unchecked - Action is required
ActField.Enabled = True 'Need to assign Action,method, & dates
End If
Next

End Sub

Any ideas for a work around?

Thanks,
Stuart
 
D

Doug Robbins - Word MVP

If you are trying to make the checkbox formfields act like radio buttons,
see the article "Making groups of Check Box Form Fields mutually exclusive
(so that they behave like radio buttons)†at:

http://www.word.mvps.org/FAQs/TblsFldsFms/ExclusiveFmFldChbxs.htm

using the following code in place of that in the article

Sub MakeCheckBoxesExclusive()
Dim oField As FormField
For Each oField In Selection.Rows(1).Range.FormFields
oField.CheckBox.Value = False
Next oField
Selection.FormFields(1).CheckBox.Value = 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, originally posted via msnews.microsoft.com
 
S

Stuart Peters

Thanks for the reply Doug, No, I am actually trying to make the form
Dynamic. The remaining fields are a mix of textboxes and Date fields.
I may just have to rebuild the tables to remove the vertically merged rows.
Is there a way to find out what rows have been merged? Maybe that is the
solution?
 
F

Fumei2 via OfficeKB.com

VBA can not actioned against merged cells. Period. It simply will not.

I am wondering about:

For Each ActField In ActiveDocument.FormFields(ffname).Range.Rows(1)

This is saying: For Each FORMFIELD in ExplicitFormfield.Range.Rows(1)

This is very odd.

The objects does not match. The IN object is a Row...not formfields. There
should be an error for this.

For Each ActField In ActiveDocument.FormFields("Text1").Range _
.Rows(1).Range.FormFields

should work though.

Unless there are merged cells.
Stuart said:
Thanks for the reply Doug, No, I am actually trying to make the form
Dynamic. The remaining fields are a mix of textboxes and Date fields.
I may just have to rebuild the tables to remove the vertically merged rows.
Is there a way to find out what rows have been merged? Maybe that is the
solution?
If you are trying to make the checkbox formfields act like radio buttons,
see the article "Making groups of Check Box Form Fields mutually exclusive
[quoted text clipped - 41 lines]
 
F

Fumei2 via OfficeKB.com

"Is there a way to find out what rows have been merged? "

Not easily. You can try checking against the ColumnIndex for the last cell,
in each row.

So if the last cell of Row1 has a ColumnIndex = 3, and the last cell of Row3
has a ColumnIndex = 2, then you know Row3 has a merged cell.

HOWEVER, you do NOT know which one, nor can you.

I avoid merged cells; they screw up VBA badly. If you need things to look
like they are merged, play around with the format of the cells (borders etc.)
rather than merge.
VBA can not actioned against merged cells. Period. It simply will not.

I am wondering about:

For Each ActField In ActiveDocument.FormFields(ffname).Range.Rows(1)

This is saying: For Each FORMFIELD in ExplicitFormfield.Range.Rows(1)

This is very odd.

The objects does not match. The IN object is a Row...not formfields. There
should be an error for this.

For Each ActField In ActiveDocument.FormFields("Text1").Range _
.Rows(1).Range.FormFields

should work though.

Unless there are merged cells.
Thanks for the reply Doug, No, I am actually trying to make the form
Dynamic. The remaining fields are a mix of textboxes and Date fields.
[quoted text clipped - 7 lines]
 
F

Fumei2 via OfficeKB.com

Oh, and it is even worse having vertical merged cells. Horizontal is bad,
but vertical is worse. It them messes up BOTH RowIndex and ColumnIndex.
"Is there a way to find out what rows have been merged? "

Not easily. You can try checking against the ColumnIndex for the last cell,
in each row.

So if the last cell of Row1 has a ColumnIndex = 3, and the last cell of Row3
has a ColumnIndex = 2, then you know Row3 has a merged cell.

HOWEVER, you do NOT know which one, nor can you.

I avoid merged cells; they screw up VBA badly. If you need things to look
like they are merged, play around with the format of the cells (borders etc.)
rather than merge.
VBA can not actioned against merged cells. Period. It simply will not.
[quoted text clipped - 20 lines]
 
D

Doug Robbins - Word MVP

You should be able to use Selection.Rows(1).Range

--
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, originally posted via msnews.microsoft.com

Fumei2 via OfficeKB.com said:
Oh, and it is even worse having vertical merged cells. Horizontal is bad,
but vertical is worse. It them messes up BOTH RowIndex and ColumnIndex.
"Is there a way to find out what rows have been merged? "

Not easily. You can try checking against the ColumnIndex for the last
cell,
in each row.

So if the last cell of Row1 has a ColumnIndex = 3, and the last cell of
Row3
has a ColumnIndex = 2, then you know Row3 has a merged cell.

HOWEVER, you do NOT know which one, nor can you.

I avoid merged cells; they screw up VBA badly. If you need things to look
like they are merged, play around with the format of the cells (borders
etc.)
rather than merge.
VBA can not actioned against merged cells. Period. It simply will not.
[quoted text clipped - 20 lines]
Thanks,
Stuart
 

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