I searched for this problem. If I missed a resolution somewhere, I apologize in advance. Here's the deal:
Every once in a while, my 06 Tacoma (V6 / Auto Trans) will not go into 4wd. It has the switch, not a shifter. If I turn the truck off, switch the key all the way on (without cranking the truck), then switch it into 4wd and start it, it engages the 4wd every time.
I am not familiar enough with what happens when I flip the switch to diagnose the problem although I do hear a clicking under the glove box when the 4wd light flashes.
I was thinking maybe that "part" that is clicking (sounds like a blinker relay) may be going bad, but I do not know what that "part" is.
And then SOMETIMES, it switches into 4wd, on the fly, just fine - as it has since I got it.
Any suggestions on what to replace first are welcomed.