Sunscreen DOES work in tanning beds.
How the Sun Produces a Tan
The sun emits ultra-violet rays that when penetrated by the skin will produce the brown pigment melanin. UVB rays are the short-wave rays that cause a sunburn to result on the surface of the skin. UVA rays are the long-wave rays that penetrate deep into the skin and produce a tan. Some combination of both rays is necessary for a tan. A tan is the body's reaction to cell damage caused by these UV rays.
How a Tanning Bed Produces a Tan
Tanning beds operate with bulbs that emit UV radiation in a spectrum similar to the sun. If you are using a sunscreen that blocks UV rays, it will also be effective in a tanning bed. It is important to note that tanning beds can emit up to twice as much skin damaging radiation as the sun.
Though wearing sunscreen when exposed to UV rays is better than wearing no sunscreen, there is no safe way to tan.