Why does the Earth have more of a gravitational force on the moon than the Sun has on the moon?

Why doesn't the sun pull the moon away from earth?

Short answer: Because the Moon is much closer to the Earth than it is to the Sun. This means the gravitational acceleration of the Earth toward the Sun is almost the same as is the gravitational acceleration of the Moon toward the Sun.

The Moon's acceleration toward the Sun, $-GM_\odot\frac{\boldsymbol R+\boldsymbol r}{||\boldsymbol R+\boldsymbol r||^3}$ is indeed about twice that of the Moon toward the Earth, $-GM_\oplus\frac{\boldsymbol r}{||\boldsymbol r||^3}$. This is irrelevant. What is relevant is the Moon's earthward acceleration due to gravitation compared to the difference between the Moon's and Earth's sunward gravitational acceleration, $$\boldsymbol a_{\odot,\text{rel}} = -GM_{\odot}\left(\frac{\boldsymbol R + \boldsymbol r}{||\boldsymbol R + \boldsymbol r||^3} - \frac{\boldsymbol R}{||\boldsymbol R||^3}\right)$$ This relative acceleration toward the Sun is a small perturbation (less than 1/87th in magnitude) on the Moon's gravitational acceleration toward the Earth. Given the current circumstances, the Sun can't pull the Moon away from the Earth.

Longer answer:

The gravitational force exerted by the Sun on the Moon is more twice that exerted by the Earth on the Moon. So why do we say the Moon orbits the Earth? This has two answers. One is that "orbit" is not a mutually exclusive term. Just because Moon orbits the Earth (and it does) does not mean that it doesn't also orbit the Sun (or the Milky Way, for that matter). It does.

The other answer is that gravitational force as-is is not a good metric. The gravitational force from the Sun and Earth are equal at a distance of about 260000 km from the Earth. The short-term and long-term behaviors of an object orbiting the Earth at 270000 km are essentially the same as those of an object orbiting the Earth at 250000 km. That 260000 km where the gravitational forces from the Sun and Earth are equal in magnitude is effectively meaningless.

A better metric is the distance at which an orbit remain stable for a long, long, long time. In the two body problem, orbits at any distance are stable so long as the total mechanical energy is negative. This is no longer the case in the multi-body problem. The Hill sphere is a somewhat reasonable metric in the three body problem.

The Hill sphere is an approximation of a much more complex shape, and this complex shape doesn't capture long-term dynamics. An object that is orbiting circularly at (for example) 2/3 of the Hill sphere radius won't remain in a circular orbit for long. Its orbit will instead become rather convoluted, sometimes dipping as close to 1/3 of the Hill sphere radius from the planet, other times moving slightly outside the Hill sphere. The object escapes the gravitational clutches of the planet if one of those excursions beyond the Hill sphere occurs near the L1 or L2 Lagrange point.

In the N-body problem (for example, the Sun plus the Earth plus Venus, Jupiter, and all of the other planets), the Hill sphere remains a reasonably good metric, but it needs to be scaled down a bit. For an object in a prograde orbit such as the Moon, the object's orbit remains stable for a very long period of time so long as the orbital radius is less than 1/2 (and maybe 1/3) of the Hill sphere radius.

The Moon's orbit about the Earth is currently about 1/4 of the Earth's Hill sphere radius. That's well within even the most conservative bound. The Moon has been orbiting the Earth for 4.5 billion years, and will continue to do so for a few more billions of years into the future.