Sorting tables containing form fields

R

Roselyn Miller

We have created a form using tables with a combination of
drop down text, merged cells, and free form text boxes.
We have encountered two problems: 1)You cannot sort a
table with merged cells. 2) You cannot sort based on a
column that has drop down text. Anyone know of any way
around this.
 
J

Jay Freedman

Hi, Roselyn,

To clarify, there's no problem in sorting tables with horizontally merged
cells. You cannot sort if you have *vertically* merged cells. In that case,
you might be able to redesign the form so that the part of the table with
the merged cells is separated from the part you're sorting, by inserting a
non-table paragraph with a font size of 1 point.

The only way you can sort on the dropdowns is to convert the fields to plain
text by unlinking them. (Of course, this is viable only if you don't need
them to function as dropdowns any more.) Here's some macro code to do that:

Sub SortEm()
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect
End If
With .Tables(1)
.Range.Fields.Unlink
.Sort
End With
.Protect wdAllowOnlyFormFields, True
End With
End Sub

You'd have to replace Tables(1) with the identification of the proper table.
The .Protect is necessary only if the document contains other fields besides
the ones in the table.
 

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