One thing is certain when you start a business--you will exit it. Your exit may be voluntary or involuntarily, well-planned and executed or a fire-sale to try and avoid disaster. This implies that if you follow a proper path, you might be able to make it a very successful exit for yourself and everyone involved. It also implies that it could go miserably wrong.
Planning for your exit should be part of the discussion when you start your business. While no one can predict what will happen, considering options and scenarios is very important, especially if you have partners.
So, when is the right time to sell your business? This really depends on your overall strategy, both personally and professionally, for yourself, your family, and others potentially involved in or impacted in some way by your business. However, just like everyone would like to fetch the highest price possible when they sell their home, I'm going to assume you approach your business the same way. The best time to sell your business is when you can get the best price for it.
Selling your business at its maximum value will have something to do with timing, just like the sale of home at the peak of the housing market. Just like a home, however, you have a lot of control over maximizing the value of your business, as well. John's Warrillow's book Built to Sell is one of my favorite works discussing this and other topics related to maximizing the value of a business. I recently wrote an article on American Express OPEN Forum teaching 5 Ways to Boost the Value of Your Business.
The main point is this: if you take a passive approach to preparing to exit your business, it will probably not work out nearly as well as if you plan at the beginning and throughout your business lifecycle for your inevitable exit.