The given sentence states two actions that happened in the past.
The
first action is in past tense 'not to drive carefully'. When the sentence has
'when' in it, it means that another past action interrupted the first one. This action is in simple past tense: "he had the accident". This action interrupted the previous one while it was happening. Hence the past action would be a continuous one.
Option A: 'Hadn't been driving' is in past perfect continuous and agrees to the given sentence as explained above. Hence option A is correct.
Option B: 'Hadn't been' is an incomplete verb form and does not contain the main verb form 'driving'.
Option C: 'Drives' is in the present tense and states a daily action.
Option D: 'Driving very' is missing the auxiliary (helping) verbs that express the tense of the sentence.
Hence options B, C and D are wrong.