A few years ago, I had a lot of soldier beetles on my tomatoes. For the last two years, I've planted some marigolds near them, and have not seen a single one.
For hornworms, I rely on hand picking and squishing them with my shoe. I am ruthless when it comes to the "bad bugs" in the garden.