You did well to recognize the issue and intervene. Job well done.
Did the situation unfold at the surface?
Was the diver your buddy?
I would not consider myself a "veteran," but here are my thoughts on the matter...
Incorrectly threaded or improperly tightened cambands will lead to this issue. In the vast majority of cases, a loose tank camband should be noticed and corrected during pre-dive checks. Pre-wetting the camband can help, since newer camband material tends to stretch a little when immersed in water. FWIW, divers using BCDs with two tank cambands (instead of one) rarely experience this issue of a "loose" tank.
If this kind of scenario were to unfold at the surface, you could tell the diver to hold up for a few seconds while you assisted. Most of the time this sort of issue reveals itself when the diver enters the water. Here in SoCal, we see it all the time during surf entries on shore dives. I've assisted entering shore divers with this issue a few times. Not a big deal really. Either we exited the water completely to make the fix or we got past the surf zone and made the fix there.
Obviously, if the loose tank occurred upon exit in the shallows (once again for shore diving), there is the option of having the diver doff the rig and carry it onto the shore. I've helped out an exiting shore diver with this problem on a couple of occasions. Both times, it was easier for him/her to doff the rig and for me to just carry the rig to shore. Bear in mind that, when asking the diver to doff his BCD in water deeper than waist/chest deep, you should be wary of how much lead the diver has and where it's positioned (on the diver in the form of weightbelt/harness or in the BCD in the form of weight-integrated pockets). You don't want to separate a negatively buoyant diver from his BCD which is allowing him to stay safely on the surface. That's a recipe for turning him into a dirt dart.
If the scenario unfolded underwater, I'd flash the "stop" sign, try to communicate what was the matter in case the diver didn't understand why the reg was being pulled from his mouth (flashing the "problem" sign, pointing to my tank, pointing to the diver), and then let him know that I was going to help.
On a few occasions with newbies underwater, I've witnessed a tank barely being held in by the camband. In such cases, I've chosen to intervene early on -- the sooner, the better.
In some cases, wrangling the tank back into the camband can be easier at a shallow depth with the diver in a prone position, preferably laying flat on the sand. Having another diver around to assist can also help things along.