A solution in closed analytic form is obtained for the motion of a charged harmonic oscillator in a variable magnetic field. The time-dependent Schr"odinger wave equation is solved in both Cartesian and polar coordinates. The canonical density matrix is calculated via the quasicoherent states.