We study an optimal investment problem for an investor who faces a dynamic risk constraint in a Markovian regime-switching environment. The goal of the investor is to maximize the expected utility of terminal wealth subject to the dynamic risk constraint specified by a proportional Value at Risk (VaR). By transforming the stochastic optimal control problem associated with the optimal investment problem into a deterministic control problem, we obtain a closed-form solution to the optimal investment problem for the case of a power utility. To evaluate the value function, we employ a numerical approximation method based on a piecewise constant approximation to the modulating Markov chain. A numerical example is given to illustrate the impact of the dynamic risk constraint on the optimal investment strategy.