The effect of a good deed is never lost, since each good deed will bring its fruit accordingly. In the 'Samyutta Nikaya' (Sagatha-vagga, Chapter I, part 8, par. 5) we read that a deva asks the Buddha how a man should live so that he does not have to fear life in another world. The Buddha answers:
[Excerpted from "Buddhist Outlook on Daily Life" written by Nina van Gorkom]
Let him but rightly set both speech and mind,A good deed can cause a happy rebirth such as birth the human plane of existence, or in a heavenly plane, and thus one need not fear life in another world. However, even a heavenly plane is not a permanent refuge. Life in a heavenly plane may last very long, but it is not permanent. There may be rebirth in 'woeful planes' after one's lifespan in a heavenly plane is terminated, depending on one's accumulated good and bad deeds. Each deed will bring its own result : a wholesome deed will bring a pleasant result and an unwholesome deed will bring an unpleasant result. Some deeds may produce a result in this life, other deeds may produce a result in a later life. The accumulated unwholesome and wholesome deeds may cause births in different planes of existence at different times. In the 'Samyutta Nikaya' ( Sagatha-vagga, Chapter III, part 2, Childless) we read about someone who gave alms to a Pacceka Buddha. Because of this good deed he was reborn in heaven seven times and after that in the human plane, which is also kusala vipaka. However, he killed his nephew because he wanted his brother's fortune. This ill deed caused him to be reborn in hell. Thus he received the results of wholesome deeds and of unwholesome deeds at different times.
And by the body work no evil things.
If in a house well stored with goods he dwell,
Let him have faith, be gentle, share his goods
With the others, and be affable of speech.
In these four qualities if he persist,
He need not fear life in another world.
[Excerpted from "Buddhist Outlook on Daily Life" written by Nina van Gorkom]