Just bought my car and had the same problem. The sunroof is getting stuck on the loose shader. Try to pull your shader out and then HOLD your sunroof button forward(stop if sun roof motor is still running). Holding it will reset the motor and it should close/ open all the way. From there you can adjust the shader and try to get it back on track and in place.
2002 BMW 330Ci