Firstly, the moon IS attracted to the sun. In fact, it is even orbiting it. Or to be precise, the earth-moon system is in orbit. read more
So, yes, the Sun is totally trying to rip the Moon away from the Earth, but the Earth is super clingy. The speed of the Moon around the Earth is about 1 km/s. At the Moon’s distance from the Earth, the escape velocity is about 1.2 km/s. read more
This has two answers. One is that "orbit" is not a mutually exclusive term. read more