Controlling the magnetism of adsorbed metal-organic molecules