In the present work, we prove an approximation result in Musielak-Orlicz-Sobolev spaces and we give an application of this approximation result to a necessary condition in the calculus of variations.