Your next pocket travel guide
Upvote:2
Flights Sweden-Latvia are effectively domestic, so you will clear immigration in Sweden, not Latvia. And yes, you can enter Schengen anywhere on your D visa.
Have your connecting boarding pass ready to present to the Swedes on request.