It is the Intention of your action and not the action itself that decides your Karma
Suppose it is dark and no one could see anything. You light up a lamp so that people could find their way in the dark. It is a service you decide to provide which is positive karma. The flame attracts the flies to it who finds a horrible death. This is a involuntary result of your action and attracts negative karma. Since your intention is positive the amount of positive karma generated is much more than the involuntary negative karma generated resulting in a positive karma
Suppose you light up the lamp with the sole intention of killing the flies, then your Intentions are destructive and negative karma will be created. Lamp may still help some people to find their way creating some positive karma. But because of negative Intention of the action, the negative karma generated is much more than the positive one
Have a positive Intention to make others happy in your actions .This will go a long way making you happy.

