There are four possible culprits:
- The vehicle speed sensor which plugs into the back of the differential
- The wiring from the speed sensor to the back of the instrument panel
- The printed circuit board on the back of the instrument cluster
- The speedometer itself
As always with electrical problems, test the simplest/cheapest component first. In this case, it's the wiring. You can run your own wiring from the sensor, up through one of the holes in the floor of the trunk (covered by rubber plugs, which you can easily remove), through the passenger compartment (through the ski passthrough if it's a sedan) and to the back of the instrument cluster. Instructions for removing the cluster and identifying the sensor wiring are here:
http://www.brickboard.com/FAQ/700-900/ElectricalInstruments.htm
Having tested with your own "known good" wiring, further problems are the fault of either the speed sensor or the speedometer/instrument cluster. Speedometer failures are common in these cars due to leaking capacitors on the speedometer's integrated circuit board (separate from the printed circuit board on the back of the instrument cluster. The 940 speedometer is made by Yazaki, for which replacement parts are difficult or impossible to find. I was only able to find two shops that claimed to be able to test and repair the gauge. They are listed in this forum post:
http://www.brickboard.com/RWD/volvo/1453661/940/960/980/V90/S90/yazaki_speedometer_repair_sources_updated.html
Replacement speed sensors cost over $100. Your best bet is to have a gauge shop bench test the gauge itself to determine if it is at fault. If the problem is intermittent, they may have to test for a long time. If necessary, the repair will cost $200–$400, not including shipping. Alternatively, if you are good at (un)soldering very small circuit board connections, you could order replacement capacitors and repair the speedometer yourself. More details about diagnosing and repairing Volvo 700/900 speedometer problems can be found here:
http://www.brickboard.com/FAQ/700-900/ElectricalInstruments.htm
A warning: Do not drive the car with the instrument cluster removed. The alternator will not charge properly without the battery warning light circuit, and you will drain your battery. I learned this the hard way.