I was always very strict about sweets. I think DS1 got them when he started going to other kids' birthday parties from school or nursery, so about aged 4. This meant DS2 got them at the same time, aged 3.
They are 6 and 7 now, and when people give us loads of sweets, or they get them from the school fair, they are allowed some, and the rest go into the sweetie tin at home. When the boys get to pick something from the sweetie tin, they are really good at only taking one or two. Obviously when they get a party bag full of sugary stuff they wolf it down.
DS1 did go through a stage of sneaking down and raiding the sweetie tin in the morning. We agreed that this was because in principle he was allowed sweets but in practice I never thought the time was right to give him one. Now they get a sweet each day at the weekend. Generally after a meal when the pudding has been fruit. If they forget I only "remember" on one of the two days.
My tip would be to make sure you have the treat with you in your bag. Then when it is sweet time, you can hand out a fun sized mars bar instead of buying an enormous one from the shop. I am not great at remembering this myself I have to say, but when it works it's good.
I know I won't be able to keep this up for ever, but I think if I hold the line as long as I can, each week is a bonus!