Programmatically embed fields of one content type in the create/edit form of another content type and store all I have drupal 6.x.  

How to programmatically (with a custom module) embed fields of one content type (content type X) in the create/edit form of another content type (content type Y) and store all the data for when the node is created/updated (store X and Y data when Y is stored).

If is not possible this in drupal 6.x I could be to work in drupal 7.x.

Thanks in advance.
I think it would be tricky as you would need a way of tracking a relationship between the two nodes as well. You would need to decide on which way the relationship would go if you were to use node reference as its only one way in drupal 6.

This is what I would do
1. Add a node reference field to Y
2. Use hook_form_alter to add the required fields (Embedding cck fields will be tricky better of just sticking to fapi fields)
3. add a custom validation handler for the x fields if required
3. Save x field values as a node programticaly when presave is triggered by hook_node_api http://api.drupal.org/api/drupal/developer!hooks!core.php/function/hook_nodeapi/6
4. Update the noderefrence in Y with the new X nid
5. Use hook_node_api to update X when Y is updated

Another possibility might be to use Rules to create and update for you