I'd go with the 9mm, it's cheaper than the .40 to shoot, has less recoil when shooting, and everyone carries 9mm ammo.
If you want more kick one day you can buy +P ammo for your 9mm, and if you're considering the protection factor in an
emergency, I know the 9mm+P Hornady Critical Duty ammo is in the same ballpark, roughly, as a standard .40 hollowpoint round. It has to be the +P Critical Duty ammo, though, not the non +P Critical Defence, which isn't as strong.
That being said, I have to agree with Martin that a 12 gauge shotgun firing buckshot is going to give someone
defending his family a lot more power and effectiveness than any pistol round.