The present invention provides a compound represented by the formula (I) :wherein each symbol is as defined in the description,or a salt thereof. The compound or a salt thereof or a prodrug thereof has a GPR40 receptor function modulating action and is useful as an insulin secretagogue or an agent for the prophylaxis or treatment of diabetes and the like.