The following example uses the Recordset property to create a new copy of the Recordset object from the currently form and then prints the names of the fields in the Debug window.
Sub Print_Field_Names()
Dim rst As DAO.Recordset, intI As Integer
Dim fld As Field
Set rst = Me.Recordset
For Each fld in rst.Fields
' Print field names.
Debug.Print fld.Name
Next
End Sub
The next example uses the Recordset property and the Recordset object to synchronize a recordset's record with the form's current record. When a company name is selected from a combo box, the FindFirst method is used to locate the record for that company, causing the form to display the found record.
Sub SupplierID_AfterUpdate()
Dim rst As DAO.Recordset
Dim strSearchName As String
Set rst = Me.Recordset
strSearchName = Str(Me!SupplierID)
rst.FindFirst "SupplierID = " & strSearchName
If rst.NoMatch Then
MsgBox "Record not found"
End If
rst.Close
End Sub
The following code helps to determine what type of recordset is returned by the Recordset property under different conditions.
Sub CheckRSType()
Dim rs as Object
Set rs=Forms(0).Recordset
If TypeOf rs Is DAO.Recordset Then
MsgBox "DAO Recordset"
ElseIf TypeOf rs is ADODB.Recordset Then
MsgBox "ADO Recordset"
End If
End Sub