A vampire is unable to enter a human home without being invited by someone who lives there. This might have been caused by some spell in the dark ages, in the same way crosses might (See here.)

There is a lot of confusion as to what a vampire can get in, and what they can't. So far, without being invited, vampires have shown being unable get into a house, or an apartment (The actual living area, the hallways outside the apartment room are allowed as they are public.) If the owner of the home is killed, then the vampire can enter. An invitation can be a gesture, written or spoken. Vampires don't need to be invited to get into schools, hospitals, offices, and motel/hotel rooms. Pretty much any public buildings, even if there are private offices or rooms inside. Apartments are basically homes inside a big building, so they don't count as being public. Motel and Hotels are different because they aren't really homes, just places to stay.

Common invitation questions:
In the episode Angel, how come a vampire is able to stick his hand in Buffy's home when it wasn't invited?
Back in the early Buffy episodes, the rules obviously weren't totally decided upon, and a vampire was allowed to stick it's hand in a door without an invite. It's as simple as that. If you want a more scientific explenation, well, when Buffy invited Angel in, maybe one could say that the vampire over heard the invitation and could get in that way.

In The Harsh Light Of Day, how were Spike and Harmony able to get into a party in someone's home?
Well, they could easily just ask someone if they were welcome to come in and join the party, or there could have been a sign out saying anyone is welcome.

How as Angel able to get into the apartment in Five by Five?
This is hard, the only thing I can think of is that Angel asked the landlord if he was allowed in, then maybe he'd have access to all the apartments.

Angel, unable to enter an apartment