>
CopyQueryDef Method
Applies To
Dynaset-Type Recordset Object, Recordset Object, Snapshot-Type Recordset Object.
Description
Returns a QueryDef object which is a copy of the QueryDef used to create the Recordset object represented by the object placeholder.
Syntax
Set <querydefobject> = <object>.CopyQueryDef
The <querydefobject> is an object variable declared as a QueryDef.
Remarks
You must first open a Recordset with the OpenRecordset method before using the CopyQueryDef method. CopyQueryDef creates a new QueryDef that is a duplicate of the QueryDef used to create the Recordset. If a QueryDef wasn't used to create this Recordset, you'll see a message that the feature is not available.
See Also
QueryDef Object.
Example (Microsoft Access)
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 Database variable pointing to current database.
Set dbs = CurrentDb
' Return QueryDef variable pointing 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
End Sub