Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Recordset in VBA? ... what purpose does it serve? [closed]

What is a Recordset in VBA?

What purpose does it serve?

How do you use them?

like image 732
Alan_AI Avatar asked Dec 18 '22 02:12

Alan_AI


2 Answers

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
like image 162
Fionnuala Avatar answered Mar 15 '23 15:03

Fionnuala


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).

like image 40
Gabriel McAdams Avatar answered Mar 15 '23 14:03

Gabriel McAdams