We investigated the influence of the relative humidity on amplitude and phase of the cantilever oscillation while operating an atomic force microscope (AFM) in the tapping mode. If the free oscillation amplitude A0 exceeds a certain critical amplitude Ac, the amplitude- and phase-distance curves show a transition from a regime with a net attractive force between tip and sample to a net repulsive regime. For hydrophilic tip and sample this critical amplitude Ac is found to increase with increasing relative humidity. In contrast, no such dependence was found for hydrophobic samples. Numerical simulations show that this behavior can be explained by assuming the intermittent formation and rupture of a capillary neck in each oscillation cycle of the AFM cantilever.