I don't believe I've ever seen it on film or print earlier than a pre-Hays Code movie.
According to the Online Etymology Dictionary, the earliest known reference to "sex" as in "intercourse" is in the writings of D.H. Lawrence in 1929, so you're right in that it's a relatively recent sense of the term etymologically-speaking.