Replacement of headlight switch
2 Answers
First suggestion: Take it to a shop that has a Modis or other full-function scan tool and have the body control module tested as it controls all lighting systems on the vehicle. Second option: Turn the switch on and manually check for power AND GROUND at the back of it at each wire. A bad ground can cause it to only work on relayed systems (as they have their own dedicated power and ground [like the headlights for example])
As a side note if the battery positive touches anything while driving (loose battery holds can let it hit the hood) then it can cause the body module to fail and can cause lighting and alarm system problems my 2004 nitro did it to me and it was a pita to figure out the cause of the repeated BCM failure