Based on this question I would like to know what the earliest source for fasting when a sefer torah falls comes from? Is is true that if a person is in the room but turns away so as not to see it fall, that that person is not obligated to fast? Where does the oft quoted '40 days' come from (I would assume it is related to kabbalas hatorah, but I have no source)?
The earliest source is the Shu"t Mishpetei Shmuel 12 quoted by the Magen Avraham 44:5. He bases it on the gemara in Moed Katan 26a that says you need to fast if you see a sefer Torah burnt in your dream. The Igros Mosheh OC 3:3 holds that according to halachah, most authorities hold that only those who drop it need to fast, but there is a minhag for those who see it to fast as well.
The gemara in moed kattan isn't talking about a dream nor about fasting– Double AA ♦Nov 11, 2012 at 6:33
The Mishpetei Shmuel I quoted was basing it on a gemara in Eilu Megalchin, although it doesn't say it explicitly. If you can suggest that his reference to Eilu Megalchin was to another page in that chapter, I would accept it, but I don't know the alternative– b aNov 11, 2012 at 7:29
See my analysis here judaism.stackexchange.com/a/22215/759– Double AA ♦Nov 11, 2012 at 7:56