Target table is already engaged in a relation.

Filed Under (alien.invasion, Visual FoxPro, work.BLOG) by WildFire on 13-10-2005

Imagine this.

You're working your arse off in a form with multiple tabs with each tab having their own reports with spider-like relationship settings in the reports' data environments.

(You use RELATIONs instead of VIEWs because you feel like VIEWs are for lazy bummers and RELATIONs are cool because they're 'old school')

Now after hours of creating, re-aligning, adjusting your reports holding more than 10 normalized tables each. You found out that after going to Tab-02 and previewing the report, going to Tab-07 fires up this error:

Target table is already engaged in a relation.

You already have SET RELATION TO in place but still the error shows.

And SET RELATION OFF won't work. I wonder why it is even included in the help file.

You 'google-d' the 'net. Taking you to places that list errors but with no definite answers because probably this was an easy problem and was solved years before.

You found a couple of links that are unrelated and refer to problems occuring only in version 4. Now you wonder if there was really a version 4 out there hidden from the minds of the humans which will be used in the up coming alien invasion.

The closest you can get is a link to Microsoft's MSDN site which you can also find in your help file.

You got irked and you tried to CLOSE DATABASES and fire up your DatabaseInitialization() routine every time you execute the print command.

But then that's too lame. Although VFP's speed is legendary and the delay is negligible... you don't want to tarnish FoxPro's name with a lame code patch manuever.

Now in case in the future someone stumbles upon this problem, decides to search the 'net, wants to join the old-school-frat (when database development tools were dedicated to speed and the proper use of resources and backward compatibility) and is allergic to views, I hope the following steps could be of help.

Fire up LIST STATUS. If it scrolls too fast, dump it in a text file.

list status to file SEXYDUMP.txt

Survey the tables with RELATIONs. Do a search on the word 'RELATION'. Note each table name and do a SET RELATION TO in every table in your noted list.

select Table01
set relation to
select Table02
set relation to

Once I can find a faster way, I'll post. Or if you have one, feel free to e-mail me... and I'll be glad to update this.

Of course... better you learn VIEWs. It's an alien technology to begin with.