Custom Function to link separate module fields based on lookups

Custom Function to link separate module fields based on lookups

Hi all, 

I've got two custom modules that both contain lookups:

1) "Customers" module, with a lookup field 'Unit' referencing "Units" Module
2) "Units" module, with a lookup field 'Current Occupant' that would change automatically based on the function.

What i'm trying to accomplish is that whenever a 'Unit' is referenced in the lookup field in the "Customers" module, I want the relevant 'Unit' to then reference that "Customer" in the 'Current Occupant' lookup field. 

Does anyone have any advice for the code I need for this as I cannot get anything to work?