by Gabio (9 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 15th April 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Create ADO recordset using another ADO recordset as template.
'create an empty recordset using oRec as template
'withAttributes - fill also attributes
'withData - fill also data
If Not ExistFields(oRec) Then
GoTo Exit_Function
End If
Dim oFld As ADODB.Field, i As Integer
For Each oFld In oRec.Fields
If withAttributes Then
Call oRecDest.Fields.Append(oFld.name, oFld.Type, oFld.DefinedSize, oFld.Attributes)
Else
Call oRecDest.Fields.Append(oFld.name, oFld.Type, oFld.DefinedSize, adFldIsNullable)
End If
Next
oRecDest.Open
If withData Then
oRec.MoveFirst
Do While Not oRec.EOF
oRecDest.AddNew
For i = 0 To oRec.Fields.Count - 1
oRecDest.Fields(i).Value = oRec.Fields(i).Value
Next i
oRec.MoveNext
Loop
End If
oRecDest.Update
Exit_Function:
Call Err.Raise(Err.Number, Err.Source, Err.Description)
End Function