I do not understand why you are using a counter at all. If you have collected the "value" names then just use them.

Is @error getting set to a non zero value on the previous read? You have no mechanism to reset it once you get an error.
_________________________
Home page: http://www.kixhelp.com/hb/