In the solar neighbourhood, there are moving groups of stars with similar ages and others of stars with heterogeneous ages as the field stars. To explain these facts, we have constructed a simple model of three phases. Phase A: a giant interstellar cloud is uniformly accelerated (or decelerated) with respect to the field stars during a relatively short period of time (10 Myr) and the cloud's mass is uniformly increased. As a result, a number of passing field stars is gravitationally captured by the cloud at the end of this phase; phase B: the acceleration (or deceleration) and mass accretion of the cloud cease. The star formation spreads throughout the cloud, giving origin to stellar groups of similar ages; and phase C: the cloud loses all its gaseous component at a constant rate and in parallel is uniformly decelerated (or accelerated) until reaching the initial velocity of phase A (case 1) or the velocity of the gas cloud remains constant (case 2). Both cases give equivalent results. The system equations for the star motions governed by a time-dependent gravitational potential of the giant cloud and referred to a coordinate system comoving with the cloud have been solved analytically. We have assumed a homogeneous spheroidal cloud of fixed semimajor axis a = 300 pc and of an initial density of 7 atoms cm −3 , with a density increment of 100 per cent and a cloud's velocity variation of 30 km s −1 , from the beginning to the end of phase A. The result is that about 4 per cent of the field stars that are passing within the volume of the cloud at the beginning of phase A are captured. The Sun itself could have been captured by the same cloud that originated the moving groups of the solar neighbourhood.