In your example, it is essential to know what "it" is.
A: "I have many weeds in my garden, how can I stop them from occurring?"

A(i): "I have many weeds in my garden, how can I stop them from happening?"
B: "When he sees you with the gun, it will occur to him that you killed John."

B(i): "When he sees you with the gun, it will happen to him that you killed John."
C: "It is almost impossible for an accident to occur."

C(i): "It is almost impossible for an accident to happen."
