Actions Are Based Upon Intention
The Prophet (Allah bless him & give him peace) said, “Verily actions are by their intentions, and one shall only have that which one intended.” [Bukhari & Muslim]The scholars mention that actions are only rewarded due to their intentions behind them.
So, in your case, you should make that intention at the moment so you can receive the reward.
Statements Of Scholars About Intentions
Imam Ibn Ata’illah (Allah have mercy upon him) said,
“Actions are lifeless forms whose souls are the secret of sincerity in them.”
Further recommended readings;
A very beautiful and more detailed article on intention;
I pray this helps and if you take just a few minutes to read the above links, it will shed a lot of light on your question.
Allah knows best.