When is it permitted to have ulterior motives along with a mitzvah?  Our Gemara on amud aleph discusses the tragic ending of Nakdimon Ben Gurion who was immensely wealthy, but became impoverished.  The Gemara wonders what could he gave done to suffer such a fate when he gave abundantly to tzeddakah? One answer given is that he did the mitzvah in order to aggrandize himself.  

Maharsha asks, did we not learn in Rosh Hashanah (4a), “One who gives charity in order that his children live is considered completely righteous.”?  Maharsha answers, that aggrandizement and honor are far worse than ordinary ulterior motives, and so Nakdimon lost his merit.  The Hafla’ah disagrees with the Maharsha because Gemara Nazir 23b rules one should study Torah even with ulterior motives, and Tosafos there explains motives such as honor and becoming renowned.  If so, why would aggrandizement be a problem?  The Hafla’ah answers that there is a difference between learning or doing a mitzvah with a goal of ultimate honor or glory that will come, versus doing the mitzvah and taking honor and glory in the process.  The former is fine because right now you are not taking any honor, and ultimately you will end up being motivated by more advanced and spiritually lofty reasons.  However, if while doing the mitzvah, one is self-promoting, it interferes with the mitzvah itself and also shortchanges the possibility for positive benefit since the engagement at the moment is contaminated by your arrogance.  Nakdimon’s downfall was that he was engaged in boosting his ego and image while doing the mitzvah of tzeddakah, disrupting his experience of the mitzvah and the merit.