You thought that you had your four-legged friend house trained, maybe even for years. Then, he or she suddenly starts having accidents—in the house. Why is your dog suddenly pooping in the house at night? And how do you help him or her understand that they need to stop?

For starters, do not yell at or physically punish your dog for this behavior. Dogs have trouble connecting delayed punishments to the behavior you want to discourage. Besides, creating more anxiety around pooping will not help your dog control him or herself. Instead, you need to figure out why they are pooping in the house at night to solve the problem. Here are some possible answers.

Age-Related Health Problems

If you have a senior dog who has been pooping outside for years, he or she knows they aren’t supposed to poop inside. Thus, he or she is likely facing medical issues that make it impossible for them to hold their bowels all night. You should refer to a vet to find out if the issue is treatable. Even if it is not, you can change your dog’s routine so that he or she eats their last meal earlier in the day and spends five or ten minutes outside right before bed, so he or she has the opportunity to go outside.

New Foods

Dogs of any age may have trouble keeping to their bathroom schedule if you have recently changed their food or gave them a new treat or some human food. If you’re changing their diet, you can expect their bowels to normalize in about two weeks. To avoid these problems next time, mix the new food with the old one for a few days to help your dog adjust.

New Problems in the Environment

You also need to consider whether your dog’s surroundings have changed to make it harder for him or her to go outside. If you’ve just moved, your dog may be confused about where they are allowed to poop. You should remind them by doing a few training sessions as if you were housetraining them for the first time. Reward them when they poop outside and bring them out frequently.

Also, consider if a new appliance or source of noise is preventing you from hearing your dog ask to go outside. Or, if something is physically in their way. For example, if your dog normally scratches on the door to be let out, and you’ve put something in front of the door, they may not know what to do to signal to you that they need to go out.

Lastly, also consider if there is a reason your dog may not want to go in the backyard. It’s not uncommon for dogs that got sprayed by a skunk to be scared to go outside, especially at night. Or, maybe a new pool or new garden bed is freaking your dog out. You may need a trainer to help solve this one.

Other Medical Reasons

If you have a young dog who hasn’t been getting into new foods and isn’t in a new environment, their indoor pooping is most likely a medical issue. Unfortunately, bowel incontinence in dogs can be a sign of several health issues, from parasites to bowel cancer. Any dog that is having trouble keeping to their washroom schedule should be checked out by a vet.