I wrote an application for a client about 4 years ago, in which I start the subform as table view, and have a button that switches it to a read-only form view. The button is located on the subform itself, and contains this:
FormViewType("", 1)
@Msg("========== SUBFORM is read-only when in table view ==========")
If you use that idea, you will also need code similar to this in the
[MySubformNameHere] :: On Form Entry event, to make the LEs read-only.
// Set or unset read-only status
If @FormViewType(sThisFormName) = 1 // Table view
or @Standalone() = 1 // Not Subform
{
// Set read-only
vElementList = @StringArrayElementList()
// Remove some elements from list so they stay accessable
vRemove = "PrevButton;NextButton;FirstButton;LastButton;F3Button;EscButton;F7Button;SimpleSearchButton;SaveButton;CommandArea;TableViewButton"
vElementList = @DifferenceStringArray(vElementList, vRemove)
n = @CountStringArray(vElementList)
For i = 1 to n
vElement = @AccessStringArray(vElementList, i)
ReadOnly( @(vElement), 2) // 0 = writable, 1 = read-only, 2 = read-only but not grayed
Next
}
Else // Form view
{
// Unset read-only
vElementList = @StringArrayElementList()
// Remove some elements from list so they stay read-only
vRemove = "MaterialCode;BOL;Date1;Warehouse;ShipmentType;RecordID;Shipped"
vElementList = @DifferenceStringArray(vElementList, vRemove)
n = @CountStringArray(vElementList)
For i = 1 to n
vElement = @AccessStringArray(vElementList, i)
ReadOnly( @(vElement), 0) // 0 = writable, 1 = read-only, 2 = read-only but not grayed
Next
}
Note that if you begin the subform as form view, you can switch to table view and back again. But, if you begin as table view, you cannot switch to form view.
I seem to remember first attempting your approach of having a form of each type, but soon ran into problems similar to what you described. And that's why I ended up going with this solution.