397 An error occurred when setting the property named 'TableName' of the object named '<>' of type 'TableFrame'.

Problem: Getting error "An error occurred when setting the property named 'TableName' of the object named '< >' of type 'TableFrame'.",

when running a form with ObjectPAL code rebinding a tableframe to a different table.
Versions: P5 and later.

Possible cause:
The error is caused by a field in the tableframe having focus, when rebinding occurs.

Example code
Changing the tableframe from Table1 to Table2 by code as:

delayScreenUpdates(Yes)
TABLE1.visible = No
TABLE1.TableName = "Table2.db" ; here appears the error
dmRemoveTable("Table1.db")
TABLE1.visible=Yes

Solution:
Focus has to be on a different object, e g the button used to execute the code.

To index