Does it only not work in certain applications? If no, it's probably a hardware issue. To rule out software, you can reboot into safemode, (think you have to press F8 key to get into safemode), and see if it works or reinstall the keyboard driver. If you have a program that allows you to set keyboard mapping, the spacebar might have been changed to something else, (this is unlikely).
On the hardware end: try using compressed air to blow the dirt out of your keyboard. Also, you can try popping the spacebar key off to see if a spring got stuck.
I can't think of any other fixes other that getting the entire keyboard replaced.