My pleasure, if you need some explanation of what the various parts of the code do, that you would like to use, just ask.
The main point is build up the SQL string one part at a time and then send it as a QueryDef to "Create" a query.
The Syntax is critical though as VBA SQL is very unforgiving.