First, does it have Electronic Shift on the Fly (ESOF) (engage 4WD with a switch) or does it have Manual Shift on Stop (engage 4WD with a lever)?
The ESOF trucks have front hubs that have two positions: "Auto" and "Lock." The hubs are engaged by a vacuum pump that applied vacuum to the hub locking it. When 2WD is selected, vacuum is again applied to the hub disengaging it. This system is known to fail once a few miles accumulate on a truck, but manually turning the hub to the "Lock" position will solve the problem temporarly.
If engaging the hubs manually does not work, the transfer case shift motor may have failed, or one of several relays or fuses may have failed.
Do the dash lights illuminate when 4WD is selected?
Do you hear any noises as if the transfer case were trying to shift?
I might be able to help, but I need a little more information.
1999 Ranger 4.0 Sport --SOLD!--
2009 F250 XLT CrewCab ShortBed
5.4L / 6 Speed / 4.10LS