To make this happen seamlessly we can turn of screen updating (called Echo in Access VBA) before closing the query and turn it on again after reopening it. Echo True The finished code looks like this [click the thumbnail to see a full-sized image]: This project makes use of a stored query and, as I mentioned at the beginning of this tutorial, one of the reasons I prefer not to rely on stored queries (if I can help it) is that they tend to get interfered with by users.
This code will replace the lines that apply the SQL string to the query and then open it. Since this query is redefined each time it is used, all we need to do it check to see if it exists before running the rest of the code.
These refinements deal with the potential problems that could occur if the user doesn't use the query in the way that you expected, and offers additional functionality: The code for these enhancements are considered separately, but a link to a complete code listing incorporating all the enhancements, as well as links to ready-made sample files can be found at the bottom of this page.
What do you want to happen if the user leaves one or more combo boxes empty?
Note that there is a space before the word Like because this is needed in the final SQL string.