The first question has not been completely answered by science yet that I know of. Vitamin D is produced in the “upper layers of skin” (maybe lower also?), so if you bath with soap to soon, you may be washing away some or all Vitamin D.
For sunbeds it depends on how the sunbed is made. Dr. Cannell once said if the bulbs used in the machine were big and round, this produces UVA and long skinny produce UVB which is what you want. If it is a combination with a little UVA and then mostly UVB that would probably be good also. THE same thing would apply, though, in that you might still “wash it away”.
If you have any more questions, just ask!