Solved Understanding Record sets

Xfree143

New member
Local time
Today, 05:20
Joined
Dec 22, 2021
Messages
2
Can anyone point me to some tutorial on record sets?
 
There are several blogs on my website which brooch on the subject of record sets.

The following link is a search of my Blog on the word "Recordset" so some of the links picked up might just be where I mention recordset, and might not be applicable to your question, but it's a good start I reckon.

 
Here is 90% of what you need.
1. How to assign and loop a recordset
2. How to edit a field in a recordset
3. How to add a record to a recordset.

Code:
Public Sub LoopRS()
  Dim rs As DAO.Recordset
  Dim strSql As String

  strSql = "Select * from tblData"
  Set rs = CurrentDb.OpenRecordset(strSql, dbOpenDynaset)

  'Loop recordset
  Do While Not rs.EOF
    'RS!FieldName
    Debug.Print rs!ID
    rs.MoveNext
  Loop

End Sub

Public Sub LopAndEditRS()
  Dim rs As DAO.Recordset
  Dim strSql As String

  strSql = "Select * from tblData"
  Set rs = CurrentDb.OpenRecordset(strSql, dbOpenDynaset)

  'Loop recordset
  Do While Not rs.EOF
    'RS!FieldName
    rs.Edit
      rs!mileage = 500
    rs.Update
    rs.MoveNext
  Loop

End Sub
Public Sub AddToRS()
  Dim rs As DAO.Recordset
  Dim strSql As String

  strSql = "Select * from tblData"
  Set rs = CurrentDb.OpenRecordset(strSql, dbOpenDynaset)

  rs.AddNew
    rs!mileage = 100
  rs.Update
End Sub

Notice the construct

Code:
Do while Not rs.eof
  rs.moveNext
Loop

Code:
Rs.Edit
   ....
rs.update

Code:
rs.Addnew
  ...
rs.update
 

Users who are viewing this thread

Back
Top Bottom