Praise be to Allah.
This condition that you stipulated in your post comes under the heading of nadhr al-lajjaaj, a vow by means of which a person aims to push himself to do something or to prevent himself from doing something. If he fulfills his oath or his vow, then there is no problem, and this basically is what is required of him, so long as he vowed or swore to do an act of obedience, because obedience is either doing something obligatory that it is haraam not to do according to the basic teachings, so he affirmed that for himself by committing himself to do it by means of the oath or vow; or it is something mustahabb (encouraged), so he is obliged to do it because of the oath or vow.
The same applies with regard to refraining from something that is haraam or makrooh (disliked).
If he breaks his oath (yameen) and does that which he swore not to do, or he fails to do that which he swore to do, then he has the choice between offering expiation for breaking his oath (kafaarat yameen), or paying the penalty he stipulated for himself in his vow.
Please see the answer to question no. 2587
Ibn Qudaamah (may Allah have mercy on him) said:
Question: making a vow which implies an oath.
If one makes a vow (nadhr) that implies an oath (yameen), in order to prevent himself or someone else from doing something, or to push himself to do something – for example, he may say: if I speak to Zayd, then I owe it to Allah to perform Hajj, or to give my wealth in charity, or to fast for one year – this is an oath (yameen), and the ruling on it is that he has the choice between fulfilling what he swore to do, in which case he does not have to do anything further, and breaking his vow (nadhr); in that case he has the choice between paying the penalty he stipulated for himself in his vow or offering expiation for breaking an oath (kafaarat yameen). This kind of vow is called nadhr al-lajjaaj at the time of anger, and he does not have to fulfil it; rather he has to fulfil nadhr at-tabarrur (a vow to do some righteous deed).
This is the view of ‘Umar, Ibn ‘Abbaas, Ibn ‘Umar, ‘Aa’ishah, Hafsah, and Zaynab bint Abi Salamah.
It was also stated by ‘Ata’, Tawoos, ‘Ikrimah, al-Qaasim, al-Hasan, Jaabir ibn Zayd, an-Nakha‘i, Qataadah, ‘Abdullah ibn Shareek, ash-Shaafa‘i, al-‘Anbari, Ishaaq, Abu ‘Ubayd, Abu Thawr and Ibn al-Mundhir.
Abu Haneefah and Maalik said: He is obliged to pay the penalty he stipulated for himself in his oath, because that is what he vowed to do and he is obliged to fulfil it, as in the case of nadhr at-tabarrur (a vow to do some righteous deed). Something similar was narrated from ash-Sha‘bi.
There is also a report narrated by ‘Imraan ibn Husayn who said: I heard the Messenger of Allah (blessings and peace of Allah be upon him) say: “There is no vow (nadhr) at a time of anger, and its expiation is the expiation for breaking an oath (kafaarat yameen).” Narrated by Sa‘eed ibn Mansoor, al-Joozajaani, in al-Mutarjam.
It was narrated from ‘Aa’ishah that the Prophet (blessings and peace of Allah be upon him) said: “Whoever swears an oath to walk (to the House of Allah), or to offer a hadiy (sacrifice), or to give his wealth for the sake of Allah or for the poor or as a gift to the Ka‘bah, then its expiation is the expiation for breaking an oath (kafaarat yameen).” Also this is the view of those whom we mentioned among the Sahaabah, and there was no one who disagreed with them during their era; and also it is an oath. Therefore this is included in the general meaning of the verse (interpretation of the meaning): “Allah will not punish you for what is unintentional in your oaths, but He will punish you for your deliberate oaths; for its expiation (a deliberate oath) feed ten Masaakeen (poor persons)…” [al-Maa’idah 5:89]. The evidence that it is an oath is that it is called by this name, and nadhr at-tabarrur (a vow to do some righteous deed) is different, because the aim behind it is to draw closer to Allah, may He be exalted, and to do deeds of righteousness, and it does not imply an oath. But in this case it does imply an oath, and it is not intended to draw closer to Allah or to do a deed of righteousness. So it is similar to an oath (yameen) in one sense, and to a vow (nadhr) in another sense. So the person has a choice between pay the penalty he stipulated for himself or offering expiation…
End quote from al-Mughni (9/505). See also: Kashf al-Qinaa‘ (6/275); ash-Sharh al-Mumti‘ (6/508)
If a person swore an oath (or made a vow) then he broke that oath (or vow), then that is the end of the matter; he only has to offer expiation once, and whatever he does after that does not require any expiation, unless he swore that every time he committed that sin, he would have to do such and such… In that case he is obliged to offer expiation every time he breaks that oath. But if he broke the oath several times and did not offer expiation each time, then one expiation is sufficient.
However what you should bear in mind before swearing an oath or making a vow, and you should focus on carefully, is the sin that you couldn't help committing and concerning which your resolve was weak, and you have become a prisoner to it. You must hasten to repent to Allah, may He be glorified and exalted, from that, and take practical measures to avoid that sin, and to close all doors that may lead you to it; you should turn to your Lord, may He be glorified and exalted, and flee to Him. Turn from disobedience towards Him to obedience, and from obedience of your nafs and your whims and desires, to obedience towards your Lord.
And Allah knows best.