Observations indicate that stars generally lose their protoplanetary discs on a timescale of about 5 Myr. Which mechanisms are responsible for the disc dissipation is still debated. Here we investigate the movement through an ambient medium as a possible cause of disc dispersal. The ram pressure exerted by the flow can truncate the disc and the accretion of material with no azimuthal angular momentum leads to further disc contraction. We derive a theoretical model from accretion disc theory that describes the evolution of the disc radius, mass, and surface density profile as a function of the density and velocity of the ambient medium. We test our model by performing hydrodynamical simulations of a protoplanetary disc embedded in a flow with different velocities and densities. We find that our model gives an adequate description of the evolution of the disc radius and accretion rate onto the disc. The total disc mass in the simulations follows the theoretically expected trend, except at the lowest density where our simulated discs lose mass owing to continuous stripping. This stripping may be a numerical rather than a physical effect. Some quantitative differences exist between the model predictions and the simulations. These are at least partly caused by numerical viscous effects in the disc and depend on the resolution of the simulation. Our model can be used as a conservative estimate for the process of face-on accretion onto protoplanetary discs, as long as viscous processes in the disc can be neglected. The model predicts that in dense gaseous environments, discs can shrink substantially in size and can, in theory, sweep up an amount of gas of the order of their initial mass. This process could be relevant for planet formation in dense environments.