I see a number of problems with your approach. Firstly, the Execute method of the database object is intended to work with SQL strings (or the name of a query), not querydefs. Secondly, if you have included all of the code for your copydata_click sub, you have not set the locally-defined querydefs at all (that is, you have not associated the querydef variables with whatever actual queries you want to execute).
If you are using DAO querydefs you can use the querydef's Execute method to execute the query (after setting the querydef to associate it with the correct query, of course).
It appears to me to be much simpler if you delete your querydef local variables defined in lines 3 to 5 and simply provide the name for each query within the Execute statement in each case branch:
- CurrentDB.Execute "Your Query Name Goes Here"
If you use Execute you can dispense with the setwarnings statements, which are not required in this case. However, in the case of a make-table query where a table of the same name already exists Execute will fail with a run-time error. This is a different behaviour than would occur where the Setwarnings statements are really needed, which is with DoCmd.RunSQL:
- SetWarnings False
-
DoCmd.RunSQL "Your Query Name Goes Here"
-
SetWarnings True
Make-table queries run by DoCmd.RunSQL will overwrite any existing version of the table concerned. If warnings are set off (as above) this is done without the user being asked to confirm the replacement.
-Stewart