I remember my parents bringing our dog to the scene of the crime and using a stern voice. A lot of it is by a schedule also, if your dog is expecting to go out every few hours then they will develop a tendency to wait.
Watch out though some behavior can't be corrected if it goes unpunished for a while. I have seen many owners who end up not being able to keep their dogs. My aunt had to give up her boxer
