Sunan an-Nasa'i, Volume 1, Book 8, Hadith 730 (DarusSalam) ⓘ
It was narrated that 'Abdul-Malik bin Sa'eed said: "I heard Abu Humaid and Abu Usaid say: 'The Messenger of Allah said: "When any one of you enters the Masjid, let him say: 'Allahumma aftahli abwaba rahmatik (O Allah, open to me the gates of your mercy). And when he leaves let him say: Allahumma inni as'aluka min fadlik (O Allah, I ask You of Your bounty).'"
أَخْبَرَنَا سُلَيْمَانُ بْنُ عُبَيْدِ اللَّهِ الْغَيْلاَنِيُّ، - بَصْرِيٌّ - قَالَ حَدَّثَنَا أَبُو عَامِرٍ، قَالَ حَدَّثَنَا سُلَيْمَانُ، عَنْ رَبِيعَةَ، عَنْ عَبْدِ الْمَلِكِ بْنِ سَعِيدٍ، قَالَ سَمِعْتُ أَبَا حُمَيْدٍ، وَأَبَا، أُسَيْدٍ يَقُولاَنِ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم " إِذَا دَخَلَ أَحَدُكُمُ الْمَسْجِدَ فَلْيَقُلِ اللَّهُمَّ افْتَحْ لِي أَبْوَابَ رَحْمَتِكَ وَإِذَا خَرَجَ فَلْيَقُلِ اللَّهُمَّ إِنِّي أَسْأَلُكَ مِنْ فَضْلِكَ " .
also referenced under: Hadith 729 (Reference) & Book 8, Hadith 42 (In-Book)