DB Recordset

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Dim dbs As DAO.

Database
Dim rst As DAO.Recordset
Dim rstFiltered As DAO.Recordset
Dim strCity As String

Set dbs = CurrentDb

'Create the first filtered Recordset, returning customer records


'for those visited between 30-60 days ago.
Set rest = dbs.OpenRecordset(_
"SELECT * FROM Customers WHERE LastVisitDate BETWEEN Date()-60 " & _
"AND Date()-30 ORDER BY LastVisitDate DESC")

'Begin row processing


Do While Not rst.EOF

'Retrieve the name of the first city in the selected rows


strCity = rst!City

'Now filter the Recordset to return only the customers from that city
rst.Filter = "City = '" & strCity & "'"
Set rstFiltered = rst.OpenRecordset

'Process the rows


Do While Not rstFiltered.EOF
rstFiltered.Edit
rstFiltered!ToBeVisited = True
rstFiltered.Update
rstFiltered.MoveNext
Loop

'We've done what was needed. Now exit


Exit Do
rst.MoveNext

Loop

'Cleanup
rstFiltered.Close
rst.Close

Set rstFiltered = Nothing


Set rst = Nothing

You might also like