One problem with programming is that it is so open ended. To answer your question (but not provide a perfect solution) would be to make a unique query so that only 1 record comes out of the filter you use.
Thus when all records print, it will be for one code only.
B