At most races other than Ascot and the Derby, the dress code is somewhat 'flexible'. Suits are sometimes recommended in certain enclosures, but often its more a matter of choice.
The most usual approach taken by men with any sense of style is to go for a fairly smart country look - heavy on tweed and, often, soft waistcoats in bold country colours. Personally, I chose my grey Donegal tweed suit. It gets relatively little use, and I like the fact that it's not quite as much of a statement as a full suit in a convention green overchecked tweed or something.
A dark green waistcoat sets this suit off nicely, and gives that all-important opportunity to get out the recently-inherited pocket watch. Other than that, I favour a slightly less aggressively 'country' shirt and tie, to slightly up the smartness and avoid looking as if I'm going on a shoot...
Off to the races? Tweed in cold weather, light grey or blue suits in the Summer. Either way, smarten up and ditch the jeans.