I hesitate to write this because so many people are sensitive, but it is an old school method that works and doesn't harm the animal. If you find a gentler method, have at it!
Assemble a kit containing: white vinegar, Tabasco sauce, and whatever you use to clean up after a mess.
When the dog has an accident, lead him to the site. There is no need to rub his nose in it or anything of the sort, just express your disapproval without yelling and getting excited. You don't want to scare him, just let him know you aren't happy. Put 1 drop of the Tabasco sauce on a finger tip and rub it on his gum above the teeth. I know it sounds tough, but it doesn't hurt. It just causes an uncomfortable puckering sensation (try it on yourself, I have). Then take him immediately outside while you clean the area. The last step is to apply the white vinegar to the cleaned area to remove the scent. It is important to start this on a weekend or whenever you can be home for a couple of days. If you follow the procedure every time he will stop very quickly. If you are intermittent in the procedure it will take much much longer to work.
I love my dogs and wouldn't have even attempted this without trying the sauce on my own gums first!