This example creates a temporary QueryDef on the Employees table and a permanent QueryDef on the Categories table, and then prints a report for each of them.
See How to Build the DAO Method Samples.
On the MSDN Library discIf you have installed the DAO SDK, see Samples\dbdaoInstallDirectory\DAOSDK\SAMPLES\CreateQueryDef.cpp.