DAO and ADO Recordset Builder
The Recordset Builder makes it very easy to create code to add, read, update or browse data in your MS Access database using DAO (or ADO):
- Select the table to work on
- Select the fields you want to access
- Select the sort of code you want to use: Add, Update, Read or Browse
- OK
The builder gives code which you have to complete in the way that suits your purposes. In the case of FindFirst you will have to specify the criteria string. Example in MS Docs Recordset.FindFirst method (DAO) In general, documentation can be found by putting the cursor in the procedure and press F1.
Concerning the fields, only select the ones you intend to use, and assign them to variables in your program as you deem fit, e.g.
Dim strSalutation as String
strSalutation = ![fldFirstName]
strSalutation = & " " & ![fldLastName]
Note: To give easy access to the DAO documentation we created an index page: https://www.codevba.com/learn-dao-vba.htm
DAO recordset Add code (example)
With values selected the following DAO code would be inserted
Dim db As DAO.Database
Set db = CurrentDb
Set rstCategories = db.OpenRecordset("Employees", dbOpenDynaset)
With rstCategories
.AddNew
![LastName] =
![FirstName] =
![HomePhone] =
![ReportsTo] =
.Update
.Close
End With
Set rstCategories = Nothing
db.Close
Set db = Nothing
DAO Recordset browse code (example)
With values selected the following DAO code would be inserted
Dim db As DAO.Database
Set db = CurrentDb
Set rstCategories = db.OpenRecordset("Employees", dbOpenDynaset)
With rstCategories
Do While Not .EOF
Debug.Print ![EmployeeID], ![LastName], ![FirstName], ![HomePhone]
.MoveNext
Loop
.Close
End With
Set rstCategories = Nothing
db.Close
Set db = Nothing