How Do You Prevent Accidents Around The House?

I have a 4 1/2 month cockapoo and as long as I’m well trained, he doesn’t have any accidents, ie. I take him out frequently enough. So how can I be sure he’s safe to go to other people’s homes and know to go to the door to go out?
When he’s in his “room”, he knows to go to the door but when I’ve let him out around the house, he “forgets” and does it right there.
So it’s frustrating as I’d like to have him with me around the house but can’t when he just does it without running to the door to get let out.
Any suggestions on how to get him to connect that going inside is not good and that he should run to the door? I know he’s on the young side but how do you train this anyway?
Thanks.
momster