Sometimes Hashem decides that despite all of a man’s efforts, they will be useless and his desires will be frustrated. Then the desired result will not be carried out...
The degree to which a man’s efforts succeed depends only on the decree of Hashem. But the efforts themselves are the tests by which a man shows whether or not he succeeds as a servant of Hashem. — Ohr Avigdor Shaar Bitachon