We attempt to extend the relation between the strengths of the interstellar CaII lines and the distances to early-type stars to objects beyond 1 kiloparsec, with the line saturation taken into account. We measure the CaII K and CaII H equivalent widths, and compute CaII column densities for 262 lines of sight towards early-type stars with available Hipparcos parallaxes (π). The targets are located within a few hundred parsecs of the Galactic plane, and span all the range of Galactic longitudes. We fit the N
CaII - parallax relation with a function of the form π=1/(a.N
CaII+b), using a maximum-likelihood approach to take account of errors in both variables. We use the resultant formula to estimate distances to stars in OB associations and clusters, and compare them to those found in the literature, usually estimated by spectrophotometric methods. For lines of sight with EW(K)/EW(H)>1.3, we obtain the following approximate formula for the distance: D
CaII=77+(2.78+(2.60)/((EW(K))/(EW(H))-0.932))EW(H), where the equivalent widths EW(K) and EW(H) are in mÅ, and the distance D
CaII in parsecs. The errors in D
CaII, resulting from the uncertainty in the fit parameters and errors in the equivalent widths, are typically about 15% of the distance. We can also expect the equation not to hold for objects situated farther than a few hundred parsecs from the Galactic plane. We find several cases of significant column density differences between association or cluster members, especially notable in the
Trumpler 16 cluster, indicating either a local contribution to the CaII column density, or background/foreground stars being confused with members. The ratio D
CaII/D
assoc appears to depend on the Galactic longitude, being highest in the range 70°<l<120° and lowest for 200°<l<300°. This effect may be due to large-scale structure being present in the CaII layer, or to the nonmember confusion being enhanced in these directions.