Halong Bay is 500km far away to Sapa so it will very hard if you transfer on the same day. There are few options below:
Option 1: By bus: you can take overnight bus from Sapa to Hanoi. You will arrive about 6:00 AM in the morning. Relax then take another day bus (about 3 hours) to Halong Bay.
Option 2: Train + Bus: Take overnight train back to Hanoi around 5:00 AM then 3 hours by bus to Halong Bay.