devxlogo

CloneFieldStructure – Create a new Recordset with same field structure

' Copy the field structure of a Recordset to a new Recordset.'' The original code has been improved to account for Numeric and Decimal' fields, that also require the setting of Precision and Numeric Scale ' properties.' Thanks to Robert Gelb for this suggestion.Function CloneFieldStructure(rs As ADODB.Recordset) As ADODB.Recordset    Dim fld As ADODB.Field    Set CloneFieldStructure = New ADODB.Recordset    ' create a set of fields with same attributes    For Each fld In rs.Fields        CloneFieldStructure.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                With CloneFieldStructure                    .Fields(.Fields.Count - 1).Precision = fld.Precision                    .Fields(.Fields.Count - 1).NumericScale = fld.NumericScale                End With        End Select        NextEnd Function

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.