UV radiation from the sun and tanning bed are generally split into two wavelengths, UVA and UVB. UVA is the predominant one and the one associated mainly with tanning, and UVB is the one most associated with skin malignancies and sunburn. UVB is thought to have a greater role in cancer induction than UVA, however, both are associated with skin cancer.
Tanning beds generally claim to utilize UVA light giving the impression that they are safer than sitting in the sun. This is misleading for several reasons. For one, there are no regulations to assure what content of UV light tanning beds are emitting. Second, although probably less dangerous than UVB, UVA is not without it's potential for skin damage.
One should cover one's body with a high SPF product when expecting sun exposure. As far as Vitamin D production is concerned, some experts claim that 15 minutes per day of sun exposure is enough to stimulate a suitable amount of Vitamin D production.