I believe what you are referencing is the hadith: “Whoever drinks alcohol and gets drunk, his prayer is not accepted from him for 40 days and if he dies he will go to Hell. But if he repents, Allah forgives him.” (Tirmidhi)
There is a difference between your prayers/salat/namaz being accepted for reward and being valid (fulfilling the requirements for a satisfactory prayer: wudu, reading Sura Al-Fatiha, etc.) This hadith mentions your prayers will not be accepted for forty days, not that your prayers for forty days will be invalid. (If you make prayer while you are intoxicated, that prayer is invalid, but if you are not intoxicated and meet the conditions for valid prayer, your prayers in the forty days are valid.)
“And those who, when they do an evil thing or wrong themselves, remember Allah and implore forgiveness for their sins – Who forgives sins save Allah only? – and will not knowingly repeat (the wrong) they did.” [Ali Imran: 135]
If you repent and seek forgiveness from Allah, both ahadith say that you will be forgiven. It is not clear if when you repent and Allah forgives you, that Allah will immediately begin accepting your prayers again (even within the forty days) or if only after those forty days will Allah accept your prayers. But it is clear that if you seek forgiveness from Allah, Allah will forgive you.
That said, in short, you are still obligated to pray on time, (and thus not further sin), repent and to seek forgiveness, even though you may not receive the reward for the prayer during those forty days, and Allah knows best.
For further reading, please see the questions and responses at IslamQA and SeekersHub.