Preventive medication is supposed to lessen the overall number of headaches and the intensity of the headaches you have. It does not relieve pain. It generally does not help if you only take it when you have a headache.
You may still get headaches even if you take preventive medication. These headaches are sometimes called breakthrough headaches. They need to be treated with symptom-relief medication.
The fact you get breakthrough headaches does not mean the preventive medication isn't working. You need to stay focused on the goal of the treatment. That goal is the overall improvement of your headaches. Remember, if the number of your headaches is even reduced by half, your preventive medicine is working.