CopyQueryDef Method Example (MDB)
The following example uses the CopyQueryDef method to return a copy of a QueryDef object representing an Invoices query, and prints the SQL property of that QueryDef object.
Sub GetQueryDefCopy()
Dim dbs As Database, rst As Recordset
Dim qdfOriginal As QueryDef, qdfCopy As QueryDef
' Return reference to current database.
Set dbs = CurrentDb
' Return reference to Invoices query.
Set qdfOriginal = dbs.QueryDefs!Invoices
' Open dynaset-type Recordset object.
Set rst = qdfOriginal.OpenRecordset
' Get copy of original QueryDef object.
Set qdfCopy = rst.CopyQueryDef
' Print value of SQL property for copy.
Debug.Print qdfCopy.SQL
rst.Close
Set dbs = Nothing
End Sub