Good day, I am a 40-year-old female, a couple of months back I had very heavy bleeding and visited the doctor. He gave me tablets to stop the bleeding for the past 3 months I did not get my period. I am not sexually active. What could be the cause.

Common problem. Irregular periods are one of the most common problems obgyns treat. If this is one time problem it usually resolves on its own. If this is a recurring problem you should be evaluated. Infections, polyps, fibroids and hormonal changes can cause spotting. There are many options available to help regulate the menstrual cycle. Schedule a visit.
Not uncommon... Not uncommon for woman to have occasional episodes of heavy bleeding (Dysfunctional Uterine Bleeding) especially with Stress &/or other Hormonal issues like low Thyroid. Though only 40 y/o early change of life hormone fluctuations can also cause this. Since the doctor gave you medication to stop bleeding it is a good idea to revisit him and ask him these questions in person. Most likely he'll tell.
Assessment. With history provided.In your age group, a full gynaecological assessment is required.This would involve a PAP smear.assessment for fibroids as well as blood tests to check your hormonal status.No bleeding for 3 months probably hormonal.