You can’t stop a swarm from happening if the colony has their mind set on it (it’s a colony’s natural response to reproducing). But on the same merit, it’s the responsibility of beekeeping to take measures to take precaution or actions to prevent it.
So we’re supposed to look out for signs of swarming - overcrowing, pollen/honey bound cells resulting in less space for queen to lay, swarm cells etc.
Queens only lay eggs (fertilised or unfertilised) as dictated by the colony and nurse bees. When the colony decides to supersede, swarm or make a queen, they feed the larvae on royal jelly and change the configuration of her cell.
The thing with swarming is that often after the first swarm, the colony will may possibly send out secondary, tertiary swarms and greatly reduce the size (health) of the colony.
Whilst capturing a swarm (and then having 2 hives) is not what you want, you could capture it - then sell it, or recombine the colonies at a later stage. This would mean euthanizing that possibly tired and old queen - but not before confirming your current hive is queen-right.
Your neighbours would appreciate not having a swarm in their roof space, wall cavity etc…