When Umbraco 4 was first released I had issues with 2 of the upgrades from v3 in that the templates disappeared from the UI and clicking on any of the DocumentTypes resulted in an exception taking the form of "No node exists with id '1040'". Today I was working on the site again and it was bugging me so I checked the forums and found this post however it wasn't resolved as far as I could tell.
I did a little digging around in the database and found some references in the cmsTemplate table to template master documents with the id 1040...bingo! I changed all references to a suitable master template that did exist and all of the above issues magically went away.
I thought it was too much of a coincidence for the node id in the exception to be the same for others as it was for me so I looked for a pattern in where this reference existed and they all seemed to be templates for what I think was the original Creative Website Starter (CWS) package. Would be interested in comments from others that might be able to confirm this.