You do a nice job of explaining what you want to do, but then:
it does not work
Bear in mind that you are sitting in front of your machine, looking at your results. We are not. I'm fresh out of dead chickens, so voodoo won't help. How does it fail to meet your expectations?

Naturally, we could copy your file into our compilers and debug it according to what we think you want, but it would be a lot easier if you guided us. Please read the second post in the "Before you make a query" thread to see the sort of things you need to clue us in on. "Doesn't work" means your machine has melted down into a slag heap of amorphous junk. If that's not the case, please clue us in.