Is one allowed to take medicine on shabbas to help prevent something? Can one for example take tums before eating a meal because he knows he will get heartburn after?
The topic of preventative medicine on Shabbos is explained in "The 39 Melochos Book" by Rabbi Dovid Ribiat (vol. 2 pg. 483). He explains that the reason the Sages forbade medicine on Shabbos is because of the concern that the anxiety due to his situation may lead him to desecrate Shabbos. This therefore only applies when one is presently suffering from an ailment. Preventative therapy however is permitted in general on Shabbos even with the use of medication. Examples of this include:
Regarding vitamins he brings an argument amongst contemporary Halachic authorities. Some (Igress Moshe OC 3:54) forbid it if has the end result of strengthning his body (and not just preventing illness) while others permit (Shmiras Shabbos Kehilchoso 34:18 footnote 76-77).