This example uses the Close method on both Recordset and Database objects that have been opened. It also demonstrates how closing a Recordset will cause unsaved changes to be lost.
Sub CloseX()
Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set rstEmployees = _
dbsNorthwind.OpenRecordset("Employees")
' Make changes to a record but close the recordset before
' saving the changes.
With rstEmployees
Debug.Print "Original data"
Debug.Print " Name - Extension"
Debug.Print " " & !FirstName & " " & _
!LastName & " - " & !Extension
.Edit
!Extension = "9999"
.Close
End With
' Reopen Recordset to show that the data hasn't
' changed.
Set rstEmployees = _
dbsNorthwind.OpenRecordset("Employees")
With rstEmployees
Debug.Print "Data after Close"
Debug.Print " Name - Extension"
Debug.Print " " & !FirstName & " " & _
!LastName & " - " & !Extension
.Close
End With
dbsNorthwind.Close
End Sub