logo
vbRad Home
Source Code
Book Reviews
Forum
Links
About Us
Contribute

Compare Databases with SQL Effects Clarity
 
 Clone Recordset Structure

Posted on
2/18/2001
Author:
Robert Gelb
Email:
Not Shown
Applies To OS:
NT, 9x, 2000
Product:
5, 6



Related Articles
Clone ADO Recordsets The Right Way

See Also: Clone the entire Recordset the right way

You would think that Recordset.Clone method would provide an option to clone a recordset structure. But, it does something else, actually. Here is how to do it yourself.



Add the following function to Module, Class or Form

Function CloneRecordsetStructure(oRs As ADODB.Recordset) As ADODB.Recordset
    Dim fld As ADODB.Field
    Dim oRsCloned As ADODB.Recordset
    
    Set oRsCloned = New ADODB.Recordset
    
    For Each fld In oRs.Fields
        oRsCloned.Fields.Append fld.Name, fld.Type, fld.DefinedSize, fld.Attributes
        
        'special handling for data types with numeric scale & precision
        Select Case fld.Type
            Case adNumeric, adDecimal
                oRsCloned.Fields(oRsCloned.Fields.Count - 1).Precision = fld.Precision
                oRsCloned.Fields(oRsCloned.Fields.Count - 1).NumericScale = fld.NumericScale
        End Select
    Next
    
    'make the cloned recordset ready for business
    oRsCloned.Open
    
    'return the new recordset
    Set CloneRecordsetStructure = oRsCloned
    
    'clean up
    Set fld = Nothing
End Function
Remarks

  • The function assumes that the original recordset exists (i.e. not equal to Nothing)




Add Your Comment  

Name: Email Address: all fields optional
Notify me via email when someone responds to this message (valid email required).

Enter the word:
 



Comments
#1. By Massimo. Posted on 3/3/2006 11:07:30 AM
Very good and clear !