It’s possible to go straight from Sapa to Halong by bus. It’ll cost you about 20usd. There’s 2 routines from Sapa to Halong: one from 11am to 9pm, the other is from 19:30 pm to 05:00 am.
However, it’ll be the most suitable for you to go Halong then Sapa. Then If you still want to visit Sapa before Halong, I have a suggestion for you.
You can book online tour to Sapa and Halong in advance with Discoveyindochina.com. You will have 3 days in Sapa for sightseeing, trekking, learning of the culture of minorities, visiting the ethnic market. Then take a night train back to Hanoi. After arriving in Hanoi station at 4.30am, we will drive you to Cinamon Hotel for early-check in. There you could take shower and have breakfast. at 8.00am driver and guide of Discoveryindochina.com will pick you up and departe to Halong Bay. Then you have 2 most amazing days in this spectacular bay.