What is a Recordset
in VBA?
What purpose does it serve?
How do you use them?
This is quite a large question. Briefly, a recordset is a selection of records from a table or query. Depending on the query used, it can be used to add, edit, delete and manipulate records. A recordset can be obtained using ADO or DAO and may have different methods and properties accordingly. Sticking to DAO, which is native to Access:
Dim rs As DAO.Recordset
Set rs=CurrentDB.OpenRecordset("Select ID, Company From Companies")
rs.Edit
rs!Company="ABC"
rs.Update
rs.AddNew
rs!Company="ABC"
rs.Update
Do While Not rs.EOF
If rs!Company="ABC" Then
''Do something
End If
rs.MoveNext
Loop
Set rs=Forms!SomeForm.RecordsetClone
rs.FindFirst "Company='ABC'"
If Not rs.NoMatch Then
Forms!SomeForm.Bookmark=rs.Bookmark
End If
A recordset is basically an in-memory container for data. You use it to manipulate data, or to pass data around.
When you read data from the database in VBA, the result will be in a recordset (with the exception of scalar data).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With