Entering into a Shul for personal needs:
A Shul is designated to be uses only for spiritual matters, such as prayer, Torah learning and general service of G-d. There are regulations emplaced in regards to using a Shul for personal use, even if one desires to only enter the Shul momentarily. The following are the laws relating to entering a Shul for personal motives. In certain cases the Sages allowed one to enter a Shul for personal motives if he learns some Torah while there. In other cases however it is forbidden to do so even if he learns Torah while there.
To call a friend: If one needs to enter into a Shul for personal use, such as to call his friend that is sitting in the Shul, he is to enter the Shul and read some Torah or orally recite a Torah thought, and only then is he to call his friend. If the person is not learned and does not know how to read then he is to ask a child [or other person] to read him a Pasuk from the child’s text of study. Alternatively, he can lengthen his stay in the Shul and then [call his friend and then] exit it.
As a shortcut: A Shul that contains two entrances may not be used as a shortcut to enter through one entrance and exit through the other entrance in order to shorten the walk towards his destination. [Some Poskim rule that this prohibition applies even if one will stop to learn some Torah in the Shul. Other Poskim however rule it is permitted in such a case.]
 Michaber 151/1; Megillah 28b
 M”B 151/4; Implication of Michaber and Megillah ibid which do not write this allowance in this case [Shaar Hatziyon 151/2]
The reason: As one is simply able to enter into a different building, and the allowance to enter into a Shul for personal use, even with the saying of a verse, was only allowed when there is no other way of fulfilling the action one desires to be done. [Shaar Hatziyon ibid]
 Michaber 151/1; Megillah ibid
 The reason: The reason one is to first learn Torah is in order so it does not appear that he is entering the Shul for his own needs. [Michaber ibid]
 The reason: As the mere sitting in a Shul is also a Mitzvah, as the verse states “Ashreiy Yoshveiy Veisecha”. [Michaber ibid]
 Michaber 151/5; Megillah 29a
 Or Sameiach Tefila 11/10; Poskim in Piskeiy Teshuvos 151/14 footnote 70
 The reason: As one is simply able to enter into a different building, and the allowance to enter into a Shul for personal use, even with the saying of a verse, was only allowed when there is no other way of fulfilling the action one desires to be done. [Shaar Hatziyon ibid]
 Biur Halacha 151/5 “Laasos Derech”