Best practice IMHO is to always type (as in define their type) your variables, especially when they are objects such as in this case. Otherwise you risk raising run time errors that won't be caught when compiling code. Only when needing to use late binding would I not type a variable. Because you have not included the DAO library in your project references, this error A user-defined data type is not defined. is raised because Access thinks you have declared a custom object without providing any properties for it. IIRC, not specifying the type also robs you of Intellisense, which is what helps you to complete a statement as it provides choices for parameters and properties.
Removing the DAO type casting is the easiest fix, but not the best one.
EDIT: rather than creating/deleting/recreating/... the query def, which can cause bloat and lead to corruption, I would simply make it a temporary query def. You do this by providing "" as its name. Alternatively, you can keep it in the navigation pane, but change its sql property each time.
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.