Hi DMBach and welcome,
I don't recommend the code you attached because it concatenates the values. Certainly, you don't need it since you can just use an InfoPath rule and eval(eval(concat(...))) to do the same thing without code.
What I do recommend is to insert the values into a separate "selected" table and then sort that table.
Qdabra (sponsor for this site) has a common library called qRules which supports both insert and sort (and over 120 other functions that could help you). I recommend installing a trial of that and looking at all of the online documentation and detailed user guide. It's very inexpensive too - probably the equivalent of 4-5 hours of your time but will save you hundreds of hours and you get our time too.
Another idea: InfoPath 2003 has a sample called Asset Tracker with built in sort functionality. It's written in javascript though, but you could probably easily port it to VB or C# .NET. Still, it would probably take you 5-10 hours and you still wouldn't have insert.
Yet another idea: there are hundreds of posts in this forum that have coding snippets in them. You could search for insert and sort and probably find some code samples.
Whatever path you take, may you have a delightful journey,
P