I have an App that looks like this

I have a form that allows users to enter data to a list called StudentManagement, based on summary info from a list called StudentList. This app also shows related info from a list called ContactDetails... All of this is working as expected. I want to include a photo of each student for reference purposes. The photos are in a Document Library called StudentPhotos. The StudentID is a Number column (it was text initially, but that gave an error).

Here is the issue, it only shows photos for some students, and sometimes the photo shows then doesn't. Here is the function I have used:

And here is a working example:

Any help would be appreciated.