It would be a bit fiddly to do with mail merge, especially if the requirement for code and number of labels was going to change each time. You would need to create a VBA process to provide the results you require.
While you are thinking about a VBA process, you could investigare a barcode tool availablefrom my web site -
http://www.gmayor.com/bar_coded_labels.htm which may suit your needs.
If the label only has a bar code, then although not designed with this application in mind, you could also use your data file with the
http://www.gmayor.com/Envelope_Label_Add_In.htm and thus select the bar codes you wish and write as many of each as you wish to the label sheet.