I recently lost my beagle after about 15 years. When he was about 8, he started having accidents and it was clear that he didn’t know what was happening until too late. The doctors put him on testosterone and after a couple of weeks it completely cleared up – but if he missed any doses, the problem would come back. They said that they did the same thing for female dogs but with estrogen and it worked the same way. It helped to firm up the muscles that controlled him going to the bathroom. Try talking to the vet about something like that.