Robert,
Thanks for the quick reply. I tried replacing my code with yours, but the link still does not work.
I have noticed the nulls in the code before, but they also exist in the layer id=0 and the link works fine for that layer where the files have been joined and exported to a file geodatabase. I only have this problem when the layer joins to a table. I need to be able to join to this table because we need the data to be live and table is being edited from another SQL front end.
Attached is my code after I edited with your code that you provided. I also changed the nulls in the Layer id=0.
Thanks,
Richard